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 INPC(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "inpc"
    __table_args__ = (
        UniqueConstraint("year", "month", "tenant_id",
                         "company_id", name="uq_inpc_year_month"),
        {"schema": "a76"}
    )

    id: Mapped[int] = mapped_column(
        Integer, primary_key=True, autoincrement=True)
        
    year: Mapped[str] = mapped_column(String(4), nullable=False)  # ANIO

    month: Mapped[str] = mapped_column(String(2), nullable=False)  # MES

    value: Mapped[Optional[Decimal]] = mapped_column(
        Numeric(19, 8), nullable=True)  # VALOR
