from sqlalchemy import Column, Integer, String, DateTime, Float, Boolean,Text
from database import Base
from datetime import datetime



class Incident(Base):
    __tablename__ = 'incidents'

    id = Column(Integer, autoincrement=True, primary_key=True)
    code = Column(String(50), nullable=False, comment='事件编号')
    title = Column(String(255), nullable=False, comment='事件标题')
    incident_type = Column(String(100), nullable=False, comment='事件类型')
    incident_level = Column(String(50), comment='事件等级')
    status = Column(String(50), default='active', comment='事件状态')
    occurrence_time = Column(DateTime, comment='事发时间')
    report_time = Column(DateTime, default=datetime.now, comment='上报时间')
    fatalities = Column(Integer, default=0, comment='死亡人数')
    injuries = Column(Integer, default=0, comment='受伤人数')
    missing = Column(Integer, default=0, comment='失联人数')
    source = Column(String(255), comment='事件来源')
    location = Column(String(255), comment='事发地点')
    longitude = Column(Float, comment='经度')
    latitude = Column(Float, comment='纬度')
    summary = Column(Text, comment='事件概要')
    recorded_by = Column(String(50), comment='记录用户ID')
    del_flag = Column(String(1), default='0', comment='删除标志（0代表存在 2代表删除）')
    contact = Column(String(50), comment='联系人')

    class Config:
        orm_mode = True

class IncidentTracking(Base):
    __tablename__ = 'incident_tracking'

    id = Column(Integer, autoincrement=True, primary_key=True)
    incident_id = Column(Integer, nullable=False, comment='事件ID')
    tracking_status = Column(String(100), nullable=False, comment='事件跟踪状态')
    tracking_time = Column(DateTime, default=datetime.now, comment='事件跟踪时间')
    notes = Column(String(500), default='', comment='备注')
    recorded_by = Column(Integer, nullable=False, comment='记录用户ID')
    del_flag = Column(String(1), default='0', comment='删除标志（0代表存在 2代表删除）')

    class Config:
        orm_mode = True

class IncidentFile(Base):
    __tablename__ = 'incident_file'

    id = Column(Integer, autoincrement=True, primary_key=True)
    file_name = Column(String(255), nullable=False, comment='文件名称')
    file_name_desc = Column(String(255), nullable=False, comment='文件名称原名')
    file_path = Column(String(255), nullable=False, comment='文件存储路径')
    file_size = Column(String(50), comment='文件大小')
    foreign_key = Column(String(50), comment='文件外键 --技术字段')
    from_scenario = Column(String(50), comment='对应标识 --技术字段')
    create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
    del_flag = Column(String(1), default='0', comment='删除标志（0代表存在 2代表删除）')  # 更新预案信息的时候 先将原有的进行备注删除

    class Config:
        orm_mode = True
