from typing import TYPE_CHECKING, Optional, List
from datetime import date
from sqlalchemy import (
    Integer, String, Date, Numeric, Boolean, 
    PrimaryKeyConstraint, ForeignKeyConstraint
)
from sqlalchemy.orm import Mapped, mapped_column, relationship
from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base

if TYPE_CHECKING:
    from api.v1.modules.a24.inv.inv_parts.models import InvPart

class InvPartAphisEntities(Base, TenantScopedMixin, TimestampMixin):
    """Módulo: entities"""
    __tablename__ = "inv_aphis_entities"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="inv_aphis_entities_pkey"),
        ForeignKeyConstraint(["aphis_general_id"], ["a24.inv_aphis_general.id"]),
        {"schema": "a24", "extend_existing": True},
    )
    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    aphis_general_id: Mapped[int] = mapped_column(Integer, nullable=False)
    
    # --- CAMPOS ENTITIES ---
    consignee_key: Mapped[Optional[str]] = mapped_column(String(50))
    broker_key: Mapped[Optional[str]] = mapped_column(String(50))
    lpco_auth_party_key: Mapped[Optional[str]] = mapped_column(String(50))
    grower_key: Mapped[Optional[str]] = mapped_column(String(50))

    aphis_general: Mapped["InvPartAphisGeneral"] = relationship(back_populates="entities")
