import enum
from sqlalchemy import TIMESTAMP, BigInteger, Column, Text, Enum as SqlEnum

from backend.app.db.base import Base


class FileTypeEnum(enum.Enum):
    PHOTO_PACK = "photo_pack"
    SITE_NOTE = "site_note"
    RD_SAP_SITE_NOTE = "rd_sap_site_note"
    PAS_2023_VENTILATION = "pas_2023_ventilation"
    PAS_2023_CONDITION = "pas_2023_condition"
    PAS_SIGNIFICANCE = "pas_significance"
    PAR_PHOTO_PACK = "par_photo_pack"
    PAS_2023_PROPERTY = "pas_2023_property"
    PAS_2023_OCCUPANCY = "pas_2023_occupancy"
    ECMK_SITE_NOTE = "ecmk_site_note"
    ECMK_RD_SAP_SITE_NOTE = "ecmk_rd_sap_site_note"
    ECMK_SURVEY_XML = "ecmk_survey_xml"
    MAGIC_PLAN_JSON = "magic_plan_json"
    IMPROVEMENT_OPTION_EVALUATION = "improvement_option_evaluation"
    MEDIUM_TERM_IMPROVEMENT_PLAN = "medium_term_improvement_plan"
    RETROFIT_DESIGN_DOC = "retrofit_design_doc"


class FileSourceEnum(enum.Enum):
    PAS_HUB = "pas hub"
    SHAREPOINT = "sharepoint"
    HUBSPOT = "hubspot"
    ECMK = "ecmk"
    MAGIC_PLAN = "magic_plan"


class UploadedFile(Base):
    __tablename__ = "uploaded_files"

    id = Column(BigInteger, primary_key=True, autoincrement=True)

    s3_file_bucket = Column(Text, nullable=False)
    s3_file_key = Column(Text, nullable=False)
    s3_upload_timestamp = Column(TIMESTAMP(timezone=True), nullable=False)

    landlord_property_id = Column(Text, nullable=True)
    uprn = Column(BigInteger, nullable=True)
    hubspot_listing_id = Column(BigInteger, nullable=True)
    hubspot_deal_id = Column(Text, nullable=True)

    file_type = Column(
        SqlEnum(
            FileTypeEnum,
            name="file_type",
            create_type=False,
            values_callable=lambda enum_cls: [e.value for e in enum_cls],
        ),
        nullable=True,
    )

    file_source = Column(
        SqlEnum(
            FileSourceEnum,
            name="file_source",
            create_type=False,
            values_callable=lambda enum_cls: [e.value for e in enum_cls],
        ),
        nullable=True,
    )
