from decimal import Decimal
from typing import Optional

from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base
from sqlalchemy import (
    DECIMAL,
    ForeignKeyConstraint,
    Integer,
    PrimaryKeyConstraint,
    String,
    UniqueConstraint,
)
from sqlalchemy.orm import Mapped, mapped_column


class Package(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "packages"  # GBultos
    __table_args__ = (
        PrimaryKeyConstraint("id", name="packages_pkey"),
        UniqueConstraint("tenant_id", "company_id", "key", name="packages_key_ukey"),
        {"schema": "a76", "extend_existing": True},
    )

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

    key: Mapped[str] = mapped_column(String(5))
    description_es: Mapped[Optional[str]] = mapped_column(String(40))
    description_en: Mapped[Optional[str]] = mapped_column(String(40))
    weight_unit: Mapped[Optional[Decimal]] = mapped_column(DECIMAL(19, 8))
    plurals: Mapped[Optional[str]] = mapped_column(String(4))
    plural_in: Mapped[Optional[str]] = mapped_column(String(4))
    code_ace: Mapped[Optional[str]] = mapped_column(String(4))
    code_aamex: Mapped[Optional[str]] = mapped_column(String(9))