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 InvPartAphisLpcos(Base, TenantScopedMixin, TimestampMixin):
    """Módulo: lpcos"""
    __tablename__ = "inv_aphis_lpcos"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="inv_aphis_lpcos_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 LPCO ---
    issuer: Mapped[Optional[str]] = mapped_column(String(100))
    issuer_loc_qua: Mapped[Optional[str]] = mapped_column(String(50))
    issuer_loc: Mapped[Optional[str]] = mapped_column(String(50))
    issuer_loc_desc: Mapped[Optional[str]] = mapped_column(String(200))
    uom: Mapped[Optional[str]] = mapped_column(String(20))
    txn_type: Mapped[Optional[str]] = mapped_column(String(50))
    type: Mapped[Optional[str]] = mapped_column(String(50))
    number: Mapped[Optional[str]] = mapped_column(String(50))
    date_qual: Mapped[Optional[str]] = mapped_column(String(50))
    date: Mapped[Optional[date]] = mapped_column(Date)
    qty: Mapped[Optional[str]] = mapped_column(String(50))

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