"""
Modelo de configuración de CFDI (Facturación Electró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 CompanyCFDI(Base, TimestampMixin):
    """Configuración de Facturación Electrónica (CFDI)"""
    
    __tablename__ = "company_cfdi"
    __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
    )
    
    # Rutas de aplicaciones y archivos
    xml_save_path: Mapped[Optional[str]] = mapped_column(String(5000))
    cfdi_app_path: Mapped[Optional[str]] = mapped_column(String(5000))
    pac_app_path: Mapped[Optional[str]] = mapped_column(String(5000))
    
    # Relación inversa
    company: Mapped["Company"] = relationship(
        "Company",
        back_populates="cfdi"
    )