"""
Modelos ORM para gestión de prevalidadores
"""

from typing import Optional

from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base
from sqlalchemy import Integer, PrimaryKeyConstraint, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column


class Prevalidator(Base, TenantScopedMixin, TimestampMixin):
    """
    Modelo para la tabla Prevalidator - Prevalidadores
    """

    __tablename__ = "prevalidators"  # GPrevalidadores
    __table_args__ = (
        PrimaryKeyConstraint("id", name="prevalidators_pkey"),
        UniqueConstraint("code", "tenant_id", "company_id",
                         name="prevalidators_code_unique"),
        {"schema": "a76"},
    )

    # Primary key
    id: Mapped[int] = mapped_column(Integer, primary_key=True)

    # Prevalidator code (unique)
    code: Mapped[str] = mapped_column(String(20), nullable=False)

    # Prevalidator information
    customs_prevalidator: Mapped[Optional[str]] = mapped_column(String(20))

    patent_prevalidator: Mapped[Optional[str]] = mapped_column(String(20))
    
    description: Mapped[Optional[str]] = mapped_column(String(50))

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