from datetime import date as Date2
from datetime import time as Time2
from typing import TYPE_CHECKING

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

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


class PedimentoPayments(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "pedimento_payments"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="pedimento_payments_pkey"),
        ForeignKeyConstraint(
            ["pedimento_id"],
            ["a76.pedimentos.id"],
            ondelete="CASCADE",
            name="fk_pedimento_payments",
        ),
        UniqueConstraint(
            "tenant_id",
            "company_id",
            "pedimento_id",
            name="pedimento_payments_pedimento_id_key",
        ),
        Index("idx_pedimento_payments_pedimento_id", "pedimento_id"),
        {"schema": "a76"},
    )

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

    acknowledgment: Mapped[str] = mapped_column(String(20))
    operation_number: Mapped[str] = mapped_column(String(14))
    bank_code: Mapped[int] = mapped_column(Integer)
    cashier: Mapped[str] = mapped_column(String(2))
    date: Mapped[Date2] = mapped_column(Date)
    time: Mapped[Time2] = mapped_column(Time)
    shift: Mapped[str] = mapped_column(String(1))
    total_cash_paid: Mapped[int] = mapped_column(Integer)
    total_contributions: Mapped[int] = mapped_column(Integer)
    counter_payment: Mapped[int] = mapped_column(SmallInteger)
    pece_code: Mapped[str] = mapped_column(String(5))

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