"""
Traducciones EN de cabeceras CSV por nombre canónico (clave interna).
Usado para plantillas descargadas locale=en y para aliases de carga.
"""


def _facturas_headers() -> dict[str, str]:
    return {
        # Encabezados / series / partidas — alineado con messages/en.json (pedimento, exchange rate, incrementables, discharge).
        "PEDIMENTO": "Pedimento",
        "REMESA": "Consignment",
        "NUMERO FACTURA": "Invoice number",
        "FECHA FACTURA": "Invoice date",
        "TIPO DE CAMBIO": "Exchange rate",
        "REGIMEN": "Regime",
        "CLAVE PROVEEDOR": "Supplier code",
        "CLAVE VENDIDO A": "Sold-to code",
        "CLAVE ENVIADO A": "Ship-to code",
        "AGENTE ADUANAL": "Customs broker",
        "CLAVE TRANSPORTISTA": "Carrier code",
        "NOMBRE CONDUCTOR": "Driver name",
        "TIPO TRANSPORTE": "Transport type",
        "CLAVE TRANSPORTE": "Transport code",
        "NUMERO CAJA": "Trailer/box number",
        "NUMERO TRANSPORTE": "Transport number",
        "TIPO MONEDA": "Currency type",
        "CLAVE MONEDA": "Currency code",
        "FLETES": "Freight",
        "VALOR SEGUROS": "Insurance value",
        "SEGUROS": "Insurance",
        "EMBALAJES": "Packaging",
        "OTROS INCREMENTABLES": "Incrementables (other)",
        "CLAVE INCOTERM": "Incoterm code",
        "PRECINTO": "Seal",
        "FECHA EMISION": "Issue date",
        "TIPO PESO": "Weight type",
        "E DOCUMENT": "E-document",
        "NUM OPERACION": "Operation number",
        "ADUANA DE CRUCE": "Customs office (crossing)",
        "OBSERVACIONES E": "Export remarks",
        "OBSERVACIONES I": "Import remarks",
        "FACTURA ALTERNA": "Alternate invoice",
        "NUM PROYECTO": "Project number",
        "ORDEN COMPRA": "Purchase order",
        "FACTURA EXPO REF": "Export invoice reference",
        "MANIFIESTO": "Manifest",
        "ENVIADO POR": "Shipped by",
        # Partidas impo temp / compartidas
        "NUMERO FACTURA EXPO": "Export invoice number",
        "LINEA": "Line",
        "LINEA EXPO": "Export line",
        "LINEA IMPO": "Import line",
        "LINEA FACTURA": "Invoice line",
        "LINEA SERIE": "Serial line",
        "TIPO DE IMPO": "Import type",
        "FACTURA IMPO": "Import invoice",
        "GENERA DESCARGA": "Generate discharge",
        "CANTIDAD EXPORTADA/DESCARGAR": "Exported qty / qty to discharge",
        "CLASE": "Class",
        "CANTIDAD IMPORTADA": "Imported quantity",
        "UNIDAD DE MEDIDA": "Unit of measure",
        "COSTO UNITARIO": "Unit cost",
        "PRECIO UNITARIO": "Unit price",
        "VALOR COMERCIAL": "Commercial value",
        "PESO NETO": "Net weight",
        "PESO BRUTO": "Gross weight",
        "CANTIDAD BULTOS": "Package count",
        "CLAVE BULTOS": "Package code",
        "PAIS ORIGEN": "Country of origin",
        "FRACCION ARANCELARIA": "Tariff fraction",
        "FRACCION": "Fraction",
        "PREFERENCIA ARANCELARIA": "Tariff preference",
        "SECTOR": "Sector",
        "FRACCION AMERICANA": "US tariff fraction",
        "ORDEN DE COMPRA": "Purchase order",
        "DESCRIPCION ESPAÑOL": "Description (Spanish)",
        "DESCRIPCION INGLES": "Description (English)",
        "DESCRIPCION": "Description",
        "MARCA": "Brand",
        "MODELO": "Model",
        "ES PARTIDA O SUBPARTIDA": "Line or sub-line",
        "ES PARTIDA/SUBPARTIDA": "Line or sub-line",
        "LINEA PRINCIPAL": "Main line",
        "NUM. PARTE": "Part number",
        "NUMPARTE": "Part number",
        "SE PAGO IMPUESTO": "Tax paid (Y/N)",
        "FORMA DE PAGO": "Payment method",
        "METODO DE VALORACION": "Valuation method",
        "DESCRIPCION EXTRA": "Extra description",
        "INFORMACION ADICIONAL": "Additional information",
        "AGREGAR/SUSTITUIR": "Add/replace",
        "AGREGAR(A)/SUSTITUIR(S)": "Add/replace",
        "TOTAL": "Total",
        "NUMERO ENTRADA": "Entry number",
        "LOTE": "Lot",
        "ID TYPE": "ID type",
        "SERIE": "Serial",
        "SUB MODELO": "Sub-model",
        "NUM PARTE": "Part number",
        "NUMERO ID": "ID number",
        "COL_EXTRA": "Extra column",
    }


def _series_merge() -> dict[str, str]:
    """Series share columns; ensure overlap with facturas_headers."""
    return {
        "NUMERO FACTURA": "Invoice number",
        "LINEA FACTURA": "Invoice line",
        "LINEA SERIE": "Serial line",
        "SERIE": "Serial",
        "MODELO": "Model",
        "NUM PARTE": "Part number",
        "SUB MODELO": "Sub-model",
        "NUMERO ID": "ID number",
        "COL_EXTRA": "Extra column",
    }


def _customs_exchange_us_fractions_boms() -> dict[str, str]:
    return {
        # customs_brokers
        "TIPO": "Type",
        "CLAVE": "Code",
        "LICENCIA": "License",
        "NOMBRE": "Name",
        "RFC": "Tax ID",
        "DIRECCION": "Address",
        "CODIGO POSTAL": "Postal code",
        "CIUDAD": "City",
        "ESTADO": "State",
        "PAIS": "Country",
        "TELEFONO": "Phone",
        "FAX": "Fax",
        "EMAIL": "Email",
        "PERSONAL_ID": "Personal ID / CURP",
        "COL_EXTRA": "Extra column",
        "POSICION": "Position",
        "EMPRESA": "Company",
        "CONTACTO": "Contact",
        # exchange_rates
        "FECHA": "Date",
        "VALOR": "Exchange rate",
        "MONEDA_LOCAL": "Local currency",
        "MONEDA_EXTRANJERA": "Foreign currency",
        # us_tariff_fractions
        "FRACCION_ARANCELARIA": "Tariff fraction",
        "PREFIJO": "Prefix",
        "UNIDAD_DE_MEDIDA": "Unit of measure",
        "DESCRIPCION": "Description",
        "TIPO_DE_ADVALOREM": "Ad valorem type",
        "ADVALOREM_PCT": "Ad valorem %",
        "ADVALOREM_DLLS": "Ad valorem (USD)",
        # boms
        "NUMPARTE_PADRE": "Parent part number",
        "NUMPARTE_COMPONENTE": "Component part number",
        "CANTIDAD": "Quantity",
        "UNIMED": "Unit of measure",
        "VERSION_BOM": "BOM version",
        "VERSION_BILL": "Bill version",
    }


def _clients_providers_headers() -> dict[str, str]:
    return {
        "PROCEDENCIA": "Origin (foreign/domestic)",
        "TIPO": "Entity type",
        "SHORT_NAME": "Short code",
        "NOMBRE": "Name",
        "RFC": "Tax ID",
        "DIRECCION": "Address",
        "NUM_EXT": "Exterior number",
        "CODIGO POSTAL": "Postal code",
        "COLONIA": "District",
        "CIUDAD": "City",
        "ESTADO": "State",
        "PAIS": "Country",
        "TELEFONO": "Phone",
        "FAX": "Fax",
        "EMAIL": "Email",
        "CURP": "CURP",
        "TIPO_PROGRAMA_SECON": "SECON program type",
        "NUM_PROGRAMA_SECON": "SECON program number",
        "FECHA_AUT_SECON": "SECON authorization date",
        "ES_PROSEC": "Is PROSEC",
        "NUM_AUT_PROSEC": "PROSEC authorization number",
        "VINCULACION": "Linkage",
        "ES_EMPRESA_CERTIFICADA": "Certified company",
        "REGISTRO_EMPRESA_CERT": "Certified company registry",
        "INFORMACION_EXTRA": "Extra information",
        "CONTACTO": "Contact",
        "MANUFACTURER_ID": "Manufacturer ID",
        "TAX_ID_PROGRAMS": "Tax ID programs",
        "BROKER_EXPO": "Export broker",
        "BROKER_IMPO": "Import broker",
        "CLAVE_TRANSFER": "Transfer code",
        "TRANSFORMA_SUBMAQ": "Transformer/sub-maquila",
        "CLAVE_WEB": "Web code",
        "COL_EXTRA": "Extra column",
        "RESPONSABLE": "Responsible",
        "POSICION": "Position",
        "INCOTERM": "Incoterm",
        "ACTIVO": "Active",
    }


def _pedimentos_headers() -> dict[str, str]:
    return {
        "AÑO": "Year",
        "PATENTE": "Patent",
        "NUMERO": "Number",
        "PEDIMENTO": "Pedimento",
        "TIPO_OPERACION": "Operation type",
        "TIPO_PEDIMENTO": "Pediment type",
        "CLAVE_PEDIMENTO": "Pediment code",
        "REGIMEN": "Regime",
        "FECHA_INICIO": "Start date",
        "FECHA_FINAL": "End date",
        "FECHA_PAGO": "Payment date",
        "FECHA_ENTRADA_RECINTO": "Compound entry date",
        "FECHA_EXTRACCION_RECINTO": "Compound exit date",
        "FECHA_RECIBIDO": "Received date",
        "FECHA_AUTORIZACION": "Authorization date",
        "FECHA_CIERRE": "Closing date",
        "FECHA_REVISION": "Review date",
        "ADUANA_SECCION_CRUCE": "Customs office / crossing section",
        "ACUSE_ELECTRONICO": "Electronic acknowledgment",
        "INDIVIDUAL_CONSOLIDADO": "Individual/consolidated",
        "MET_TRANSP_ENTRADA": "Inbound transport method",
        "MET_TRANSP_ARRIVO": "Arrival transport method",
        "MET_TRANSP_SALIDA": "Outbound transport method",
        "IEPS": "IEPS",
        "IEPS_2": "IEPS (2)",
        "DTA": "DTA",
        "DTA_2": "DTA (2)",
        "CNT": "CNT",
        "CNT_2": "CNT (2)",
        "PREVALIDACION": "Pre-validation",
        "MONTO_TIGIE": "TIGIE amount",
        "PAGO_IMPUESTO": "Tax paid (Y/N)",
        "ES_MIXTO": "Mixed (yes/no)",
        "OBS_RECTIFICA": "Rectification remarks",
        "OPCION_DESTINO": "Destination option",
        "VALOR_IVA": "VAT value",
        "VALOR_ME": "Foreign currency value",
        "VALOR_ADUANAS": "Customs value",
        "VALOR_USD": "USD value",
        "VALOR_SEGUROS": "Insurance value",
        "FLETE": "Freight",
        "SEGUROS": "Insurance",
        "EMBALAJES": "Packaging",
        "OTROS_INCREMENTABLES": "Incrementables (other)",
        "ESTATUS": "Status",
        "PERSONA_REV": "Reviewer",
        "OBSERVACIONES": "Remarks",
        "TIPO_CAMBIO": "Exchange rate",
        "REPRESENTANTE_AA": "Customs broker representative",
        "CLIENTE_SHORT_NAME": "Client short code",
        "CLAVE_DEST_ORIGEN": "Destination origin code",
        "IDENTIFICADORES": "Identifiers",
        "CUOTAS_COMPENSATORIAS": "Compensatory quotas",
        "ERRORES": "Errors",
        "MULTAS": "Fines",
        "RECARGOS": "Surcharges",
        "PRECIO_PAGADO": "Price paid",
        "PESO_BRUTO": "Gross weight",
        "IVA_DE_PREV": "VAT from pre-validation",
        "IVA_2": "VAT (2)",
        "IGI_2": "IGI (2)",
        "FORMA_PAGO_IVA": "VAT payment method",
        "FORMA_PAGO_IVA_2": "VAT payment method (2)",
        "FORMA_PAGO_IGI": "IGI payment method",
        "FORMA_PAGO_IGI_2": "IGI payment method (2)",
        "FORMA_PAGO_IEPS_2": "IEPS payment method (2)",
        "FORMA_PAGO_DTA": "DTA payment method",
        "FORMA_PAGO_DTA_2": "DTA payment method (2)",
        "FORMA_PAGO_CNT_2": "CNT payment method (2)",
        "FORMA_PAGO_PREVAL": "Pre-validation payment method",
        "FORMA_PAGO_PREVALIDACION_2": "Pre-validation payment method (2)",
    }


def _vehicles_drivers_trailers_transporters() -> dict[str, str]:
    return {
        # vehicles / transports template "vehicles"
        "CLAVE": "Code",
        "CODIGO DE ENTIDAD": "Entity code",
        "TIPO TRANSPORTE": "Transport type",
        "CLAVE TRANSPORTE": "Transport code",
        "CLAVE ACE": "ACE code",
        "PLACAS": "Plates",
        "PRECINTO": "Seal",
        "NUMERO DOT": "DOT number",
        "TRANSPONDEDOR": "Transponder",
        "VIN": "VIN",
        "EMPRESA ASEGURADORA": "Insurance company",
        "NUM. ASEGURADORA": "Insurance policy number",
        "FECHA DE ASEGURADORA": "Insurance date",
        "MONTO ASEGURADO": "Insured amount",
        "COL_EXTRA": "Extra column",
        # drivers
        "TRANSPORTISTA": "Carrier",
        "LINEA": "Line",
        "CLAVE CONDUCTOR": "Driver code",
        "NOMBRE(S)": "Given name(s)",
        "APELLIDO PATERNO": "Last name (paternal)",
        "SEXO": "Gender",
        "FECHA NACIMIENTO": "Birth date",
        "PAIS NACIMIENTO": "Birth country",
        "LICENCIA": "License",
        "FORMA IDENTIFICACION 1": "ID type 1",
        "NUM. IDENTIFICACION 1": "ID number 1",
        "FORMA IDENTIFICACION 2": "ID type 2",
        "NUM. IDENTIFICACION 2": "ID number 2",
        "IDENTIFICACION ACE": "ACE identification",
        "PAIS": "Country",
        "PAIS 2": "Country 2",
        "ESTADO": "State",
        "ESTADO 2": "State 2",
        "PERMISO LINEA EXPRESS": "Express line permit",
        "PERMISO MAT. PELIGROSO": "Hazmat permit",
        "TRANSPORTA MAT. PELIGROSO?": "Transports hazardous material?",
        # trailers
        "NUMERO TRAILER": "Trailer number",
        "TIPO TRAILER": "Trailer type",
        "CODIGO ENTIDAD": "Entity code",
        "CLAVE CONTENEDOR": "Container code",
        # transporters
        "CLAVE TRANSPORTISTA": "Carrier code",
        "NOMBRE CORTO": "Short name",
        "RESPONSABLE": "Responsible",
        "RFC": "Tax ID",
        "CALLES": "Street address",
        "CODIGO CAAT": "CAAT code",
        "CODIGO CARGADOR": "Loader code",
        "CODIGO TRANS": "Transport code",
        "TIPO INTERFASE TRANS": "Carrier interface type",
        "SERVIDOR FTP": "FTP server",
        "USUARIO FTP": "FTP user",
        "CLAVE ACCESO FTP": "FTP password",
        "DIRECTORIO FTP": "FTP directory",
    }


def _material_classes_headers() -> dict[str, str]:
    # Coincide con classes/template_config.TEMPLATE_DOWNLOAD_HEADERS_EN (salvo columnas solo en template extendido).
    return {
        "CLASE": "CLASS CODE",
        "DESCRIPCIONE": "DESCRIPTION (SPANISH)",
        "DESCRIPCIONI": "DESCRIPTION (ENGLISH)",
        "CLAVEMAT": "MATERIAL TYPE",
        "UNIMED": "COMMERCIAL UOM",
        "FRACCION": "MX FRACTION",
        "FRACCIONAME": "US FRACTION",
        "TASADEPRECIA": "DEPRECIATION RATE",
        "CLAVESUB": "SUB KEY",
        "REVFISICA": "PHYSICAL REVIEW (1/0)",
        "FRACCIONEXENTAIVA": "PRODUCT/SERVICE CP CODE",
    }


def _parts_headers() -> dict[str, str]:
    # Alineado con parts/template_config.TEMPLATE_DOWNLOAD_HEADERS_EN.
    return {
        "NUMPARTE": "PART NUMBER",
        "NUMPARTECOM": "COMMERCIAL PART NUMBER",
        "DESCRIPCIONE": "DESCRIPTION (SPANISH)",
        "DESCRIPCIONI": "DESCRIPTION (ENGLISH)",
        "CLASE": "CLASS",
        "UNIMED": "COMMERCIAL UNIT OF MEASURE",
        "COSTOUNIT": "UNIT COST",
        "TIPOMONEDA": "COST CURRENCY TYPE",
        "CLAVEMONEDA": "CURRENCY CODE",
        "PESOUNIT": "UNIT WEIGHT",
        "TIPOPESO": "WEIGHT TYPE",
        "FRACCION": "FRACTION",
        "FRACCIONAME": "US FRACTION",
        "PAIS": "COUNTRY",
        "PREFERENCIA": "PREFERENCE",
        "SECTOR": "SECTOR",
        "RUTAIMAGEN": "IMAGE PATH",
        "FDAKEY": "FDA key",
        "FCCKEY": "FCC key",
        "LICENCIA": "License code",
        "ECCN": "ECCN",
        "EXPORTCODE": "Export code",
        "EXCLUSION": "Exclusion",
        "ACTIVO": "Active",
    }


def _merge_all() -> dict[str, str]:
    merged: dict[str, str] = {}
    for part in (
        _facturas_headers(),
        _series_merge(),
        _customs_exchange_us_fractions_boms(),
        _clients_providers_headers(),
        _pedimentos_headers(),
        _vehicles_drivers_trailers_transporters(),
        _material_classes_headers(),
        _parts_headers(),
    ):
        merged.update(part)
    return merged


HEADER_LABEL_EN: dict[str, str] = _merge_all()
