from typing import Optional
from decimal import Decimal
from sqlalchemy import Integer, String, UniqueConstraint, Numeric
from sqlalchemy.orm import Mapped, mapped_column
from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base


class CustomsBrokerConcept(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "customs_broker_concepts"
    __table_args__ = (
        UniqueConstraint("broker_key", "concept", "company_id", name="uq_broker_concept"),
        {"schema": "a76"}
    )

    id: Mapped[int] = mapped_column(
        Integer, primary_key=True, autoincrement=True)

    company_id: Mapped[int] = mapped_column(Integer, nullable=False)

    broker_key: Mapped[str] = mapped_column(
        String(5), nullable=False)  # CLAVEAA

    concept: Mapped[str] = mapped_column(
        String(15), nullable=False)  # CONCEPTO

    amount: Mapped[Optional[Decimal]] = mapped_column(
        Numeric(11, 2), nullable=True)  # IMPORTE

    priority: Mapped[Optional[int]] = mapped_column(
        Integer, nullable=True)  # PRIORIDAD
