"""PPT 定期產出執行紀錄模型。"""

from datetime import datetime

from sqlalchemy import Column, DateTime, Integer, String, Text

from database.models import Base


class PPTGenerationRun(Base):
    """每次日/週/月/季/半年/年度 PPT 產出嘗試。"""

    __tablename__ = "ppt_generation_runs"

    id = Column(Integer, primary_key=True)
    schedule_kind = Column(String(40), nullable=False, index=True)
    report_type = Column(String(50), nullable=False, index=True)
    target_label = Column(String(160))
    status = Column(String(30), nullable=False)
    parameters_json = Column(Text)
    file_path = Column(String(500))
    file_size = Column(Integer)
    error_msg = Column(Text)
    result_payload = Column(Text)
    started_at = Column(DateTime, default=datetime.now, index=True)
    finished_at = Column(DateTime)

    def __repr__(self):
        return (
            f"<PPTGenerationRun(kind={self.schedule_kind}, "
            f"type={self.report_type}, status={self.status})>"
        )
