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 InvPartAphisCharacteristic(Base, TenantScopedMixin, TimestampMixin):
    """Módulo: Item characteristic"""
    __tablename__ = "inv_aphis_characteristic"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="inv_aphis_characteristic_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 CARACTERISTICAS ---
    item_id: Mapped[Optional[str]] = mapped_column(String(50))
    number_from: Mapped[Optional[str]] = mapped_column(String(50))
    number_to: Mapped[Optional[str]] = mapped_column(String(50))
    category_type: Mapped[Optional[str]] = mapped_column(String(50))
    commodity_qua: Mapped[Optional[str]] = mapped_column(String(50))
    commodity_char_qua: Mapped[Optional[str]] = mapped_column(String(50))
    description: Mapped[Optional[str]] = mapped_column(String(200))
    category_code: Mapped[Optional[str]] = mapped_column(String(50))

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