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 (
    Index,
    Integer,
    Numeric,
    PrimaryKeyConstraint,
    SmallInteger,
    String,
)
from sqlalchemy.orm import Mapped, mapped_column


class ValueManifestation(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "value_manifestations"
    __table_args__ = (
        Index("idx_value_manifestations_manifestation_number", "manifestation_number"),
        {"schema": "a76"},
    )

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    
    manifestation_number: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    pedimento: Mapped[Optional[str]] = mapped_column(String(15), nullable=True)
    periodicity: Mapped[Optional[str]] = mapped_column(String(10), nullable=True)
    semester: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    year: Mapped[Optional[str]] = mapped_column(String(4), nullable=True)
    pedimento_type: Mapped[Optional[str]] = mapped_column(String(3), nullable=True)
    aa_code: Mapped[Optional[str]] = mapped_column(String(5), nullable=True)
    patent: Mapped[Optional[str]] = mapped_column(String(4), nullable=True)
    first_name: Mapped[Optional[str]] = mapped_column(String(80), nullable=True)
    last_name_paternal: Mapped[Optional[str]] = mapped_column(String(80), nullable=True)
    last_name_maternal: Mapped[Optional[str]] = mapped_column(String(80), nullable=True)
    methods_count: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
    merchandise_value_method: Mapped[Optional[str]] = mapped_column(String(10), nullable=True)
    transaction_value: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    identical_merchandise_value: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    similar_merchandise_value: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    unit_sale_price_value: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    reconstructed_value: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    article_78_value: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    provisional_value_declaration: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
    has_attachments: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    attachment_pages_number: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    transaction_value_paid_price: Mapped[Optional[Decimal]] = mapped_column(Numeric(19, 8), nullable=True)
    price_pre_invoice: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    price_other_docs: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    concept_article_66: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    concept_article_66_breakdown: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
    attachment_article_66: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    prepaid_merchandise_article_65: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    attachment_article_65: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    tax_base_no_sale: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    exists_circumstances_article_67_71: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    customs_value_attachment: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    provisional_value_determination: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    merchandise_value_proof_attachment: Mapped[Optional[str]] = mapped_column(String(2), nullable=True)
    legal_rep_rfc: Mapped[Optional[str]] = mapped_column(String(30), nullable=True)
    legal_representative: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    date: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
    selected_invoice: Mapped[Optional[str]] = mapped_column(String(20), nullable=True)
    invoice_option: Mapped[Optional[str]] = mapped_column(String(3), nullable=True)
    importer_to_use: Mapped[Optional[str]] = mapped_column(String(8), nullable=True)
