from decimal import Decimal
from typing import Optional

from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base
from sqlalchemy import (
    Boolean,
    ForeignKeyConstraint,
    Integer,
    Numeric,
    PrimaryKeyConstraint,
    String,
)
from sqlalchemy.orm import Mapped, mapped_column


class QClasses(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "fa_classes"  # QClases
    __table_args__ = (
        PrimaryKeyConstraint("id", name="qclases_pk"),
        ForeignKeyConstraint(
            ["class_id"], ["a76.classes.id"], name="fk_qclasses_classes"
        ),
        {"schema": "a24"},
    )

    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    class_id: Mapped[int] = mapped_column(Integer, nullable=False)

    import_tariff_code: Mapped[Optional[str]] = mapped_column(
        String(10), nullable=True
    )  # FRACCIONIMPO
    import_tariff_type: Mapped[Optional[str]] = mapped_column(
        String(6), nullable=True
    )  # TIPOFRACIMPO
    export_tariff_code: Mapped[Optional[str]] = mapped_column(
        String(10), nullable=True
    )  # FRACCIONEXPO
    export_tariff_type: Mapped[Optional[str]] = mapped_column(
        String(6), nullable=True
    )  # TIPOFRACEXPO
    depreciation_rate: Mapped[Optional[Decimal]] = mapped_column(
        Numeric(5, 2), nullable=True
    )  # TASADEPRECIA
    fda_code: Mapped[Optional[str]] = mapped_column(String(20), nullable=True)  # FDA
    eccn_code: Mapped[Optional[str]] = mapped_column(String(20), nullable=True)  # ECCN
    class_enabled: Mapped[bool] = mapped_column(
        Boolean, default=True, server_default="true", nullable=False
    )  # HABILITADESHABILITACLASE
