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 InvPartAphisStypePitems(Base, TenantScopedMixin, TimestampMixin):
    """Módulo: stype_Pitems"""
    __tablename__ = "inv_aphis_stype_pitems"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="inv_aphis_stype_pitems_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 STYPE PITEMS ---
    source_type_code: Mapped[Optional[str]] = mapped_column(String(50))
    country_code: Mapped[Optional[str]] = mapped_column(String(3))
    geo_location: Mapped[Optional[str]] = mapped_column(String(100))
    processing_start: Mapped[Optional[date]] = mapped_column(Date)
    processing_end: Mapped[Optional[date]] = mapped_column(Date)
    processing_type: Mapped[Optional[str]] = mapped_column(String(50))
    processing_desc: Mapped[Optional[str]] = mapped_column(String(200))

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