"""
Modelo de configuración de Ventanilla Única
"""
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 CompanyVU(Base, TimestampMixin):
    """Configuración de Ventanilla Única"""
    
    __tablename__ = "CompanyVU"
    __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
    )
    
    # Credenciales
    webservice_user: Mapped[Optional[str]] = mapped_column(String(100))
    webservice_password: Mapped[Optional[str]] = mapped_column(String(100))
    email: Mapped[Optional[str]] = mapped_column(String(800))
    
    # Configuración
    figure_type: Mapped[Optional[str]] = mapped_column(String(29))
    central_path: Mapped[Optional[str]] = mapped_column(String(1499))
    xml_files_path: Mapped[Optional[str]] = mapped_column(String(1499))
    
    # RFC y validación
    query_rfc: Mapped[Optional[str]] = mapped_column(String(30))
    validation_rfc: Mapped[Optional[str]] = mapped_column(String(30))
    
    # Otras configuraciones
    configuration_source: Mapped[Optional[str]] = mapped_column(String(30))
    measurement_units: Mapped[Optional[str]] = mapped_column(String(3))
    
    # Relación inversa
    company: Mapped["Company"] = relationship(
        "Company",
        back_populates="ventanilla_unica"
    )