"""Report Model.""" from datetime import datetime from typing import Optional from sqlalchemy import Enum from sqlalchemy.orm import Mapped, mapped_column from collaborator.connectors import mysql from collaborator.constants.reports import ( FileFormat, NumberFormat, ReportSource, TriggerType, ) class ReportRun(mysql.BaseModel): """Encapsulates a collaborator report. Represents a collaborator revenue split report in the collaborator database. """ __tablename__ = "report_run" report_run_id: Mapped[int] = mapped_column("id", primary_key=True) uuid: Mapped[str] name: Mapped[str] period_ids: Mapped[str] period_name: Mapped[str] # Use enum values (e.g. "xls"), instead of SQLAlchemy default of names (e.g. "XLS") file_format: Mapped[Optional[FileFormat]] = mapped_column( Enum(FileFormat, values_callable=lambda x: [i.value for i in x]), default=FileFormat.XLS, ) requested_datetime: Mapped[datetime] source: Mapped[ReportSource] = mapped_column( Enum(ReportSource), default=ReportSource.LEGACY ) requestor_identity_uuid: Mapped[Optional[str]] snowflake_query_id: Mapped[Optional[str]] notification_email: Mapped[Optional[str]] # Use enum values (e.g. "us"), instead of SQLAlchemy default of names (e.g. "US") number_format: Mapped[Optional[NumberFormat]] = mapped_column( Enum(NumberFormat, values_callable=lambda x: [i.value for i in x]) ) trigger_type: Mapped[Optional[TriggerType]] = mapped_column(Enum(TriggerType)) def to_dict(self): """Report run data dictionary.""" return { "id": self.report_run_id, "report_run_uuid": self.uuid, "report_run_name": self.name, "period_ids": self.period_ids, "period_name": self.period_name, "file_format": self.file_format, "requested_datetime": self.requested_datetime.isoformat(), "source": self.source, "requestor_identity_uuid": self.requestor_identity_uuid, "notification_email": self.notification_email, "number_format": self.number_format, "trigger_type": self.trigger_type, }