from typing import List, Optional, Any
from pydantic import BaseModel, Field

class Mainx30GenerationRequest(BaseModel):
    """
    Schema for the Mainx30 file generation request
    """
    manifiestos: List[str] = Field(..., description="Lista de números de manifiesto a procesar")
    nomenclatura_factura: bool = Field(False, description="Usar nomenclatura basada en factura")
    consolidar_rbs: bool = Field(False, description="Consolidar por fracción RB System")
    emanifest_fast_blanco: bool = Field(False, description="E-Manifest y FAST en blanco")
    no_enviar_emanifest: bool = Field(False, description="No enviar E-Manifest")
    consolidar_partidas: bool = Field(False, description="Consolidar partidas (XML OPTIMA Y RBS2)")
    main_x40_emanifest: bool = Field(False, description="Main X40 E-Manifest")
    main_x30_fedex: bool = Field(False, description="Main X30 (FEDEX)")
    iv11: bool = Field(False, description="IV11")
    iv42: bool = Field(False, description="IV42")

class ErrorValidacion(BaseModel):
    """
    Schema for validation errors during file generation
    """
    partida: int
    linea: int
    descripcion: str
    soluciones: str
    identificador: str
    campos: str = ""
    campos2: str = ""

class Mainx30Response(BaseModel):
    """
    Schema for the generation response
    """
    success: bool
    message: str
    task_id: Optional[str] = None
    archivo_generado: Optional[str] = None
    ruta_archivo: Optional[str] = None
    content: Optional[str] = None
    
    # Statistics
    cuenta_partidas: int = 0
    valor_total: float = 0.0
    flete_total: float = 0.0
    peso_bruto_total: float = 0.0
    peso_neto_total: float = 0.0
    cuenta_facturas: int = 0
    
    # Validation
    errores: List[ErrorValidacion] = []
    tiene_inconsistencias: bool = False

class BrokerValidationResult(BaseModel):
    es_valido: bool
    mensaje_error: Optional[str] = None
    broker_cliente: Optional[str] = None

class EmpresaDatos(BaseModel):
    broker: str
    responsable: str
    rfc: str
    tiene_linea_express: str
    nombre_empresa: str = "AAKRON RULE CORPORATION"
    manufacturer_id: str = "I10900" 
    ftp_key: str = "00SCSI"

class ConfiguracionSistema(BaseModel):
    path_arch_transmision: str
    utilizar_nombre_generico_mainx30: bool
    utilizar_codigo_broker_cliente: bool
