from schemas.base_imports import (
    CrudCollection,
    String,
    Integer,
    Boolean,
    ForeignKey,
    Index,
    TIMESTAMP,
    Numeric,
    SmallInteger,
    mapped_column,
    Mapped,
)


class BuildIbans(CrudCollection):
    """
    BuildParts class based on declarative_base and BaseMixin via session
    """

    __tablename__ = "build_ibans"
    __exclude__fields__ = []

    iban: Mapped[str] = mapped_column(
        String(40), server_default="", nullable=False, comment="IBAN number"
    )
    start_date: Mapped[TIMESTAMP] = mapped_column(
        TIMESTAMP(timezone=True), nullable=False, comment="Bank Transaction Start Date"
    )
    stop_date: Mapped[TIMESTAMP] = mapped_column(
        TIMESTAMP(timezone=True), server_default="2900-01-01 00:00:00"
    )
    bank_code: Mapped[str] = mapped_column(String(24), server_default="TR0000000000000")
    xcomment: Mapped[str] = mapped_column(String(64), server_default="????")
    build_id: Mapped[int] = mapped_column(
        ForeignKey("build.id"), nullable=True, comment="Building ID"
    )
    build_uu_id: Mapped[str] = mapped_column(
        String, nullable=True, comment="Building UUID", index=True
    )

    __table_args__ = (
        Index("_build_ibans_ndx_01", iban, start_date, unique=True),
        {"comment": "IBANs related to money transactions due to building objects"},
    )


class BuildIbanDescription(CrudCollection):
    """
    SearchComments class based on declarative_base and CrudCollection via session
    """

    __tablename__ = "build_iban_description"
    __exclude__fields__ = []

    iban: Mapped[str] = mapped_column(String, nullable=False, comment="IBAN Number")
    group_id: Mapped[int] = mapped_column(
        SmallInteger, nullable=False, comment="Group ID"
    )
    search_word: Mapped[str] = mapped_column(
        String, nullable=False, comment="Search Word", index=True
    )
    customer_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
    customer_uu_id: Mapped[str] = mapped_column(
        String, nullable=True, comment="Customer UUID"
    )
    company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=True)
    company_uu_id: Mapped[str] = mapped_column(
        String, nullable=True, comment="Company UUID"
    )
    build_parts_id: Mapped[int] = mapped_column(
        ForeignKey("build_parts.id"), nullable=True
    )
    build_parts_uu_id: Mapped[str] = mapped_column(
        String, nullable=True, comment="Build Parts UUID"
    )

    __table_args__ = (
        Index(
            "_search_iban_description_ndx_00", iban, search_word, group_id, unique=True
        ),
        {"comment": "Search Iban Description Information"},
    )
