from typing import TYPE_CHECKING, List

from core.database import Base
from sqlalchemy import PrimaryKeyConstraint, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

if TYPE_CHECKING:
    from ..code_pedimento_regimens.models import CodePedimentoRegimen


class RegimenPedimento(Base):
    __tablename__ = "pedimento_regimens"  # GRegimenPed
    __table_args__ = (
        PrimaryKeyConstraint("code", name="pedimento_regimens_pkey"),
        {"schema": "public", "extend_existing": True},
    )

    code: Mapped[str] = mapped_column(
        String(3), nullable=False
    )  # código tipo "01", "31"
    description: Mapped[str] = mapped_column(
        String(100), nullable=False
    )  # nombre legal en español

    # Relación con Claves de Pedimento
    # GClavePedRegimen
    claves_pedimento: Mapped[List["CodePedimentoRegimen"]] = relationship(
        "CodePedimentoRegimen", uselist=True, back_populates="regimen"
    )

    def __repr__(self):
        return f"<RegimenPedimento(code={self.code}, description={self.description})>"
