"""
Modelos para fracciones arancelarias americanas
"""

from datetime import datetime
from typing import Optional

from sqlalchemy import String, Numeric, TIMESTAMP, func
from sqlalchemy.orm import Mapped, mapped_column

from core.database import Base
from api.v1.common.base_models import TenantScopedMixin, TimestampMixin


class USTariffFraction(Base, TenantScopedMixin, TimestampMixin):
    """Modelo para fracciones arancelarias americanas (US HTS codes)"""

    __tablename__ = "us_tariff_fractions"
    __table_args__ = {"schema": "a76"}

    # Primary Key
    id: Mapped[int] = mapped_column(primary_key=True, index=True)

    # Datos principales
    code: Mapped[str] = mapped_column(
        String(16), nullable=False, comment="Código de fracción americana"
    )
    prefix: Mapped[Optional[str]] = mapped_column(
        String(10), comment="Prefijo de clasificación"
    )
    type_code: Mapped[Optional[str]] = mapped_column(
        String(10), comment="Código de tipo"
    )
    ad_valorem: Mapped[Optional[float]] = mapped_column(
        Numeric(10, 2), comment="Porcentaje ad valorem"
    )
    fixed_cost: Mapped[Optional[float]] = mapped_column(
        Numeric(15, 8), comment="Tasa fija"
    )
    unit_of_measure: Mapped[Optional[str]] = mapped_column(
        String(10), comment="Unidad de medida"
    )
    description: Mapped[Optional[str]] = mapped_column(
        String, comment="Descripción de la fracción"
    )

    def __repr__(self):
        return f"<USTariffFraction {self.code}>"
