"""
Modelo de configuración del Prevalidador Aduanal
"""
from typing import Optional, TYPE_CHECKING
from sqlalchemy import Integer, String, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from core.database import Base
from api.v1.common.base_models import TimestampMixin

if TYPE_CHECKING:
    from ..models import Company


class CompanyPrevalidator(Base, TimestampMixin):
    """Configuración de Prevalidador Aduanal"""
    
    __tablename__ = "company_prevalidator"
    __table_args__ = {"schema": "a76"}
    
    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    company_id: Mapped[int] = mapped_column(
        ForeignKey("a76.company.id", ondelete="CASCADE"),
        nullable=False,
        unique=True,
        index=True
    )
    
    # Información del prevalidador
    customs: Mapped[Optional[str]] = mapped_column(String(20))
    key: Mapped[Optional[str]] = mapped_column(String(20))
    patent: Mapped[Optional[str]] = mapped_column(String(4))
    description: Mapped[Optional[str]] = mapped_column(String(100))
    
    # Relación inversa
    company: Mapped["Company"] = relationship(
        "Company",
        back_populates="prevalidator"
    )