"""
Modelos ORM para gestión de avisos electrónicos
"""

from typing import Optional

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


class ElectronicNotice(Base, TenantScopedMixin, TimestampMixin):
    """
    Modelo para la tabla ElectronicNotice - Avisos Electrónicos
    """

    __tablename__ = "electronic_notices"  # GAvisosElectronicos
    __table_args__ = (
        PrimaryKeyConstraint("id", name="electronic_notices_pkey"),
        {"schema": "a76"},
    )

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

    # Notice identification
    notice_number: Mapped[Optional[str]] = mapped_column(String(500))
    year: Mapped[Optional[str]] = mapped_column(String(20))
    patent: Mapped[Optional[str]] = mapped_column(String(4))
    pedimento: Mapped[Optional[str]] = mapped_column(String(15))

    # Files
    file_sent: Mapped[Optional[str]] = mapped_column(String(1000))
    file_response: Mapped[Optional[str]] = mapped_column(String(1000))

    # Status and validation
    status: Mapped[Optional[str]] = mapped_column(String(100))
    invoice: Mapped[Optional[str]] = mapped_column(String(50))
    validation_acknowledgment: Mapped[Optional[str]] = mapped_column(
        String(20))

    # Certificate information
    fea: Mapped[Optional[str]] = mapped_column(String(1000))
    certificate_number: Mapped[Optional[str]] = mapped_column(String(50))

    def __repr__(self):
        return f"<ElectronicNotice(id={self.id}, notice_number={self.notice_number}, status={self.status})>"
