from typing import TYPE_CHECKING

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

if TYPE_CHECKING:
    from api.v1.modules.a76.pedmientos.models.pedimentos import Pedimentos


class PedimentoContributions(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "pedimento_contributions"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="pedimento_contributions_pkey"),
        ForeignKeyConstraint(
            ["pedimento_id"],
            ["a76.pedimentos.id"],
            ondelete="CASCADE",
            name="fk_pedimento_contributions",
        ),
        {"schema": "a76"},
    )

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

    contribucion: Mapped[str | None] = mapped_column(String(50), nullable=True)
    tipo_tasa: Mapped[str | None] = mapped_column(String(100), nullable=True)
    tasa: Mapped[Numeric | None] = mapped_column(Numeric(15, 8), nullable=True)
    forma_pago: Mapped[str | None] = mapped_column(String(50), nullable=True)
    importe: Mapped[Numeric | None] = mapped_column(Numeric(17, 2), nullable=True)
    gravamen: Mapped[str | None] = mapped_column(String(100), nullable=True)
    abreviacion: Mapped[str | None] = mapped_column(String(50), nullable=True)
    forma_pago_2: Mapped[str | None] = mapped_column(String(50), nullable=True)
    importe_2: Mapped[Numeric | None] = mapped_column(Numeric(17, 2), nullable=True)

    pedimento: Mapped["Pedimentos"] = relationship(
        "Pedimentos", back_populates="pedimento_contributions"
    )
