"""
Field Mappings - Auto-generated from FIELD_DEFINITIONS.

All mappings in this file are derived from field_config.FIELD_DEFINITIONS.
This ensures consistency across the entire codebase.

DO NOT hardcode field mappings elsewhere - always import from this module.
"""

from typing import Final

from .field_config import FIELD_DEFINITIONS


# List of class names in order (for YOLO classes.txt generation)
# Index matches class_id: CLASS_NAMES[0] = "invoice_number"
CLASS_NAMES: Final[list[str]] = [fd.class_name for fd in FIELD_DEFINITIONS]

# class_id -> class_name mapping
# Example: {0: "invoice_number", 1: "invoice_date", ...}
FIELD_CLASSES: Final[dict[int, str]] = {
    fd.class_id: fd.class_name for fd in FIELD_DEFINITIONS
}

# class_name -> class_id mapping (reverse of FIELD_CLASSES)
# Example: {"invoice_number": 0, "invoice_date": 1, ...}
FIELD_CLASS_IDS: Final[dict[str, int]] = {
    fd.class_name: fd.class_id for fd in FIELD_DEFINITIONS
}

# class_name -> field_name mapping (for API responses)
# Example: {"invoice_number": "InvoiceNumber", "ocr_number": "OCR", ...}
CLASS_TO_FIELD: Final[dict[str, str]] = {
    fd.class_name: fd.field_name for fd in FIELD_DEFINITIONS
}

# field_name -> class_id mapping (for CSV import)
# Excludes derived fields like payment_line
# Example: {"InvoiceNumber": 0, "InvoiceDate": 1, ...}
CSV_TO_CLASS_MAPPING: Final[dict[str, int]] = {
    fd.field_name: fd.class_id for fd in FIELD_DEFINITIONS if not fd.is_derived
}

# field_name -> class_id mapping (for training, includes all fields)
# Example: {"InvoiceNumber": 0, ..., "payment_line": 9}
TRAINING_FIELD_CLASSES: Final[dict[str, int]] = {
    fd.field_name: fd.class_id for fd in FIELD_DEFINITIONS
}

# field_name -> class_name mapping (reverse of CLASS_TO_FIELD)
# Example: {"InvoiceNumber": "invoice_number", "OCR": "ocr_number", ...}
FIELD_TO_CLASS: Final[dict[str, str]] = {
    fd.field_name: fd.class_name for fd in FIELD_DEFINITIONS
}

# Account field mapping for supplier_accounts special handling
# BG:xxx -> Bankgiro, PG:xxx -> Plusgiro
ACCOUNT_FIELD_MAPPING: Final[dict[str, dict[str, str]]] = {
    "supplier_accounts": {
        "BG": "Bankgiro",
        "PG": "Plusgiro",
    }
}
