
from datetime import datetime
from typing import Optional
from sqlalchemy import String, Numeric, TIMESTAMP, func, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from core.database import Base

from api.v1.common.base_models import TenantScopedMixin, TimestampMixin

class CanadianTariffFraction(Base, TenantScopedMixin, TimestampMixin):
    """Model for Canadian Tariff Fractions (GFracEUACan)"""
    __tablename__ = "canadian_tariff_fractions"
    __table_args__ = (
        UniqueConstraint('fraction', 'country_code', 'company_id', name='uq_canadian_fraction_country_company'),
        {"schema": "a76"}
    )

    id: Mapped[int] = mapped_column(primary_key=True, index=True)
    
    # FRACCION
    fraction: Mapped[str] = mapped_column(String(13), nullable=False, index=True)
    # ADV
    ad_valorem: Mapped[Optional[float]] = mapped_column(Numeric(5, 2))
    # UNIDAD
    unit_of_measure: Mapped[Optional[str]] = mapped_column(String(5))
    # CLAVEM3 (Part of original PK)
    country_code: Mapped[str] = mapped_column(String(3), nullable=False, index=True)
    # DESCRIPCION
    description: Mapped[Optional[str]] = mapped_column(String(1000))
