"""
Modelo de configuración del Agente Aduanal Electrónico
"""
from typing import Optional, TYPE_CHECKING
from sqlalchemy import Integer, String, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from core.database import Base
from api.v1.common.base_models import TimestampMixin

if TYPE_CHECKING:
    from ..models import Company


class CompanyElectronicAgent(Base, TimestampMixin):
    """Configuración de Agente Aduanal Electrónico"""
    
    __tablename__ = "company_electronic_agent"
    __table_args__ = {"schema": "a76"}
    
    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    company_id: Mapped[int] = mapped_column(
        ForeignKey("a76.company.id", ondelete="CASCADE"),
        nullable=False,
        unique=True,
        index=True
    )
    
    # Carpetas
    input_folder: Mapped[Optional[str]] = mapped_column(String(1000))
    output_folder: Mapped[Optional[str]] = mapped_column(String(1000))
    
    # Máscaras y extensiones
    send_mask: Mapped[Optional[str]] = mapped_column(String(20))
    response_mask: Mapped[Optional[str]] = mapped_column(String(20))
    response_extension: Mapped[Optional[str]] = mapped_column(String(20))
    
    # Contadores
    counter_start: Mapped[Optional[int]] = mapped_column(Integer)
    counter_end: Mapped[Optional[int]] = mapped_column(Integer)
    counter_next: Mapped[Optional[int]] = mapped_column(Integer)
    
    # Relación inversa
    company: Mapped["Company"] = relationship(
        "Company",
        back_populates="electronic_agent"
    )