from sqlalchemy import Column, Integer, TIMESTAMP, DateTime, String, JSON
from sqlalchemy import func as func_sql
from app.entity.database.base import Base

# class PowerOutageStats(Base):
#     """
#     停电统计数据表 ORM 模型
#     """
#     __tablename__ = 'power_outage_stats'  # 表名
#
#     # 定义字段
#     id = Column(Integer, primary_key=True, autoincrement=True, comment='主键ID')
#     province_company = Column(String(100), nullable=False, comment='省公司')
#     outage_users = Column(Integer, nullable=False, comment='停电用户数')
#     outage_ratio = Column(String(100), nullable=False,comment='停电环比（百分比）')
#     short_outage_users = Column(Integer, comment='短时停电用户数')
#     outage_user_ratio = Column(String(100), nullable=False,comment='停电用户占本单位比例（百分比）')
#     repair_count = Column(Integer, comment='故障抢修数')
#     repair_arrival_time = Column(String(100), nullable=False,comment='故障抢修到位时间（小时）')
#     repair_completion_time = Column(String(100), nullable=False, comment='故障抢修完成时间（小时）')
#     complaint_count = Column(Integer, comment='投诉数量')
#     complaint_ratio = Column(String(100), nullable=False,comment='投诉环比（百分比）')
#     public_opinion_count = Column(Integer, comment='舆情数量')
#     public_opinion_ratio = Column(String(100), nullable=False,comment='舆情环比（百分比）')
#     major_event_count = Column(Integer, comment='重大事件数量')
#     statistics_time = Column(Date, nullable=False,comment='统计时间')
#     created_at = Column(TIMESTAMP, server_default=func_sql.now(), comment='记录创建时间')
#     updated_at = Column(TIMESTAMP, server_default=func_sql.now(), onupdate=func_sql.now(), comment='记录更新时间')


# 日报存储路径
class DailyReport(Base):
    """
    将日报/简报以二进制的形式保存到数据库
    """

    __tablename__ = "daily_report"

    # 定义字段
    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
    report_title = Column(String(100), nullable=False, comment="日报标题")
    daily_report = Column(String(100), nullable=False, comment="日报保存路径")
    daily_repo_simple = Column(String(100), nullable=False, comment="简报保存路径")
    save_folder = Column(String(100), nullable=False, comment="保存的子文件夹")
    statistics_time = Column(
        DateTime, nullable=False, comment="统计时间", unique=True, index=True
    )
    created_at = Column(
        TIMESTAMP, server_default=func_sql.now(), comment="记录创建时间"
    )
    updated_at = Column(
        TIMESTAMP,
        server_default=func_sql.now(),
        onupdate=func_sql.now(),
        comment="记录更新时间",
    )

    # daily_repo_simple_excel = Column(String(100), nullable=False,comment='简报excel保存路径')
    # img = Column(String(100), nullable=False,comment='图片保存路径')
    def to_dict(self):
        return {
            "id": self.id,
            "report_title": self.report_title,
            "daily_report": self.daily_report,
            "daily_repo_simple": self.daily_repo_simple,
            "save_folder": self.save_folder,
            "statistics_time": self.statistics_time.strftime("%Y-%m-%d %H:%M:%S"),
            "created_at": self.created_at.strftime("%Y-%m-%d %H:%M:%S"),
            "updated_at": self.updated_at.strftime("%Y-%m-%d %H:%M:%S"),
            # 'daily_repo_simple_excel':self.daily_repo_simple_excel,
            # 'img':self.img
        }


# 原始文件存储路径
class DailyReportRawdata(Base):
    """
    将日报/简报以二进制的形式保存到数据库
    """

    __tablename__ = "daily_report_rawdata"

    # 定义字段
    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
    report_title = Column(String(100), nullable=False, comment="日报标题")
    save_folder = Column(String(100), nullable=False, comment="保存的子文件夹")
    # sentiment_doc = Column(String(100), nullable=False,comment='舆情word原始文件保存路径')
    # complaint_doc = Column(String(100), nullable=False,comment='投诉word原始文件保存路径')
    # complaint_tb = Column(String(100), nullable=False,comment='投诉excel原始文件保存路径')
    # power_off_tb = Column(String(100), nullable=False,comment='停电excel原始文件保存路径')
    raw_data_path = Column(JSON, nullable=False, comment="原始文件保存路径")
    statistics_time = Column(
        DateTime, nullable=False, comment="统计时间", unique=True, index=True
    )
    created_at = Column(
        TIMESTAMP, server_default=func_sql.now(), comment="记录创建时间"
    )
    updated_at = Column(
        TIMESTAMP,
        server_default=func_sql.now(),
        onupdate=func_sql.now(),
        comment="记录更新时间",
    )

    # daily_repo_simple_excel = Column(String(100), nullable=False,comment='简报excel保存路径')
    # img = Column(String(100), nullable=False,comment='图片保存路径')
    def to_dict(self):
        return {
            "id": self.id,
            "report_title": self.report_title,
            "save_folder": self.save_folder,
            "raw_data_path": self.raw_data_path,
            "statistics_time": self.statistics_time.strftime("%Y-%m-%d %H:%M:%S"),
            "created_at": self.created_at.strftime("%Y-%m-%d %H:%M:%S"),
            "updated_at": self.updated_at.strftime("%Y-%m-%d %H:%M:%S"),
            # 'daily_repo_simple_excel':self.daily_repo_simple_excel,
            # 'img':self.img
        }
