from typing import TYPE_CHECKING

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

if TYPE_CHECKING:
    from api.v1.modules.a76.pedmientos.models.pedimentos import Pedimentos


class PedimentoConfigUpdateRectification(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "pedimento_config_update_rectification"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="pedimento_config_update_rectification_pkey"),        
        ForeignKeyConstraint(
            ["pedimento_id"],
            ["a76.pedimentos.id"],
            ondelete="CASCADE",
            name="fk_pedimento_config_update_rectification",
        ),
        UniqueConstraint(
            "tenant_id",
            "company_id",
            "pedimento_id",
            name="pedimento_config_update_rectification_pedimento_id_key",
        ),
        {"schema": "a76"},
    )

    id: Mapped[int] = mapped_column(Integer)
    pedimento_id: Mapped[int] = mapped_column(Integer, nullable=False)

    update_vat: Mapped[bool] = mapped_column(Boolean, default=False, server_default='false')
    update_advalorem: Mapped[bool] = mapped_column(Boolean, default=False, server_default='false')
    update_dta: Mapped[bool] = mapped_column(Boolean, default=False, server_default='false')
    update_cc: Mapped[bool] = mapped_column(Boolean, default=False, server_default='false')
    update_ieps: Mapped[bool] = mapped_column(Boolean, default=False, server_default='false')
    calculate_surcharge: Mapped[bool] = mapped_column(Boolean, default=False, server_default='false')

    pedimento: Mapped["Pedimentos"] = relationship(
        "Pedimentos", back_populates="pedimento_config_update_rectification"
    )
