from datetime import date, datetime from sqlalchemy import JSON, Date, DateTime, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.constants import ActorValue from app.core.database import Base from app.core.utils.time import utc_now from app.modules.business.constants import ( SourceSystem, StatusValue, ) from app.modules.business.models.common import TimestampMixin class WorkReport(Base, TimestampMixin): __tablename__ = "work_reports" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) code: Mapped[str] = mapped_column(String(64), unique=True, index=True) report_type: Mapped[str] = mapped_column(String(32), index=True) title: Mapped[str] = mapped_column(String(255), index=True) reporter: Mapped[str] = mapped_column(String(128), default=ActorValue.SYSTEM, index=True) department: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) project_code: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True) period_start: Mapped[date] = mapped_column(Date, index=True) period_end: Mapped[date] = mapped_column(Date, index=True) content: Mapped[str] = mapped_column(Text) metrics: Mapped[dict | None] = mapped_column(JSON, nullable=True) risk_summary: Mapped[dict | None] = mapped_column(JSON, nullable=True) status: Mapped[str] = mapped_column(String(64), default=StatusValue.GENERATED, index=True) source_system: Mapped[str] = mapped_column(String(64), default=SourceSystem.INTERNAL) class ReportPushRun(Base, TimestampMixin): __tablename__ = "report_push_runs" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) code: Mapped[str] = mapped_column(String(64), unique=True, index=True) report_type: Mapped[str] = mapped_column(String(64), index=True) title: Mapped[str | None] = mapped_column(String(255), nullable=True) receive_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) receive_id_type: Mapped[str] = mapped_column(String(64), index=True) status: Mapped[str] = mapped_column(String(32), index=True) task_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) actor: Mapped[str] = mapped_column(String(128), default=ActorValue.SYSTEM, index=True) provider_response: Mapped[dict | None] = mapped_column(JSON, nullable=True) error_message: Mapped[str | None] = mapped_column(Text, nullable=True) queued_at: Mapped[datetime] = mapped_column(DateTime, default=utc_now, index=True) sent_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)