from typing import Dict, List, Union

# Display names for each group heading 
MOTHERBOARD_DISPLAY_NAMES: Dict[str, str] = {
    "key-specs":       "Key Specifications",
    "general":         "General",
    "compatibility":   "Compatibility",
    "connectivity":    "Connectivity",
    "ports":           "Ports",
    "memory":          "Memory",
    "dimensions":      "Dimensions & Weight",
    "expansion":       "Expansion",
    "firmware":        "Firmware",
    "software":        "Software",
    "power":           "Power",
    "environment":     "Environmental",
    "compliance":      "Compliance",
    "security":        "Security",
    "others":          "Other Specifications",
}

#boxpc display‑names
BOXPC_DISPLAY_NAMES: Dict[str, str] = {
    "key-specs":       "Key Specifications",
    "general":         "General",
    "compatibility":   "Compatibility",
    "connectivity":    "Connectivity & I/O",
    "ports":           "Ports",
    "memory":          "Memory & Storage",
    "firmware":        "Firmware",
    "power":           "Power",
    "environment":     "Environmental",
    "compliance":      "Certifications & Standards",
    "security":        "Security",
    "others":          "Other Specifications",
    "Storage":         "Storage",
    "Audio":           "Audio",
    "Rear I/O (Key Specs)": "Rear I/O (Key Specs)",
    "Front I/O":       "Front I/O",
    "LED Indicators":  "LED Indicators",
    "AI Accelerator":  "AI Accelerator",
    "Operating System Support": "Operating System Support",
    "Dimensions Length & Width": "Dimensions Length & Width",
    "Dimensions Height": "Dimensions Height",
    "Mounting":        "Mounting",
    "Material Used":   "Material Used",
    "Country of Origin": "Country of Origin",
}


#Flat grouping map for “motherboard”
MOTHERBOARD_SPEC_KEY_TO_CATEGORY: Dict[str, str] = {
    "Supported Processor":                     "key-specs",
    "Chipset":                                  "key-specs",
    "RAM (Memory)":                             "key-specs",

    #General
    "Graphics Controller":                      "general",
    "Supported Displays":                       "general",

    #Compatibility
    "Operating System Support":                 "compatibility",

    #Connectivity
    "Ethernet - Number of ports":               "connectivity",
    "Rear I/O - Ethernet":                      "connectivity",
    "Rear I/O - USB":                           "connectivity",
    "Rear I/O - Display":                       "connectivity",
    "Internal I/O - Serial":                    "connectivity",
    "Internal I/O - USB":                       "connectivity",
    "Internal I/O - Display":                   "connectivity",
    "Internal I/O - Audio":                     "connectivity",
    "Internal I/O - SATA":                      "connectivity",
    "Internal I/O - NVDS":                      "connectivity",
    "Internal I/O - DIO":                       "connectivity",

    #Ports
    "Rear I/O - Ethernet":                      "ports",
    "Rear I/O - USB":                           "ports",
    "Rear I/O - Display":                       "ports",

    #Memory
    "RAM (Memory)":                             "memory",

    #Dimensions & Weight
    "Dimensions Length and Width - Inches":     "dimensions",
    "Dimensions Length and Width - Millimeters":"dimensions",
    "Dimensions Height":                        "dimensions",

    #Expansion
    "Expansion Interface":                      "expansion",

    #Firmware
    "BIOS":                                     "firmware",

    #Power
    "Power - Type (DC, ATX) Volts, Ranging":    "power",
    "Power - Connector (DC-in Jack, ATX)":     "power",
    "Power - Power Consumption":               "power",

    #Environmental
    "Temperature - Operating":                  "environment",
    "Temperature - Storage":                    "environment",
    "Humidity - Operating":                     "environment",
    "Humidity - Storage":                       "environment",
    "MTBF":                                     "environment",

    #Compliance
    "Regulatory Certifications (Example: FCC Class B, CE, UKCA)": "compliance",
    "Environmental (REACH, ROHS, EU POP, etc.)":                "compliance",

    #Security
    "Security (TPM)":                           "security",
}


#Flat grouping map for “box-pc”
BOXPC_SPEC_KEY_TO_CATEGORY: Dict[str, str] = {
    #Key Specs
    "Supported Processor":                     "key-specs",
    "Chipset":                                  "key-specs",
    "RAM (Memory)":                             "key-specs",
    "BIOS":                                     "firmware",

    #General
    "Graphics Controller":                      "general",
    "Supported Displays":                       "general",

    #Compatibility
    "Operating System Support":                 "compatibility",

    #Connectivity & I/O
    "Ethernet – Number of Ports":               "connectivity",
    "Ethernet – Controller":                    "connectivity",
    "Rear I/O - Ethernet":                      "Rear I/O (Key Specs)",
    "Rear I/O - USB":                           "Rear I/O (Key Specs)",
    "Rear I/O - Display":                       "Rear I/O (Key Specs)",
    "Front I/O - Ethernet":                     "Front I/O",
    "Front I/O - Serial":                       "Front I/O",
    "Front I/O - USB":                          "Front I/O",
    "Front I/O - Display":                      "Front I/O",
    "Front I/O - DIO":                          "Front I/O",
    "Front I/O - Power":                        "Front I/O",
    "Front I/O - Audio":                        "Front I/O",
    "Front I/O - Buttons":                      "Front I/O",
    "Rear I/O - Serial":                        "Rear I/O",
    "Rear I/O - DIO":                           "Rear I/O",
    "Rear I/O - Power":                         "Rear I/O",
    "Rear I/O - Audio":                         "Rear I/O",
    "Rear I/O - Buttons":                       "Rear I/O",
    "Rear I/O - Antenna":                       "Rear I/O",
    "Rear I/O - SIM":                           "Rear I/O",

    #Memory & Storage
    "Storage - Internal":                       "Storage",
    "Storage - External":                       "Storage",
    "RAM (Memory)":                             "memory",

    #Audio
    "Audio":                                    "Audio",
    "LED Indicators":                           "LED Indicators",

    #AI
    "AI Accelerator":                           "AI Accelerator",

    #Power
    "Power - Type (DC, ATX) Volts, Ranging":    "power",
    "Power - Connector (DC-in Jack, ATX)":     "power",
    "Power - Power Consumption":               "power",

    #Environmental
    "Temperature - Operating":                  "Temperature",
    "Temperature - Storage":                    "Temperature",
    "Humidity - Operating":                     "Humidity",
    "Humidity - Storage":                       "Humidity",

    #Compliance & Standards
    "Regulatory Certifications (Example: FCC Class B, CE, UKCA)": "Certifications",
    "Environmental (REACH, ROHS, EU POP, etc.)":                "compliance",
    "Standards - Shock":                       "Standards",
    "Standards - Vibration":                   "Standards",
    "Standards - IP Rating":                   "Standards",

    #Others
    "MTBF":                                     "others",
    "Dimensions Length and Width - Millimeters":"Dimensions Length & Width",
    "Dimensions Length and Width - Inches":     "Dimensions Length & Width",
    "Dimensions Height":                        "Dimensions Height",
    "Mounting":                                 "Mounting",
    "Material used (Example: steel, aluminum)": "Material Used",
    "Country of Origin":                        "Country of Origin",
}


#Explicit ordering & nesting for each category
MOTHERBOARD_KEY_SPECS_ORDER: List[Union[str, Dict[str, List[str]]]] = [
    {"Key Specifications": ["Supported Processor", "Chipset"]},
    {"Memory": ["RAM (Memory)"]},
    {"Firmware": ["BIOS"]},
    {"Expansion": ["Expansion Interface"]},
    {"Security": ["Security (TPM)"]},
    {"Compatibility": ["Operating System Support"]},
    {"General": ["Supported Displays", "Graphics Controller"]},
    {"Connectivity": [
        "Ethernet - Number of ports",
        "Rear I/O - Ethernet",
        "Rear I/O - USB",
        "Rear I/O - Display",
        "Internal I/O - Serial",
        "Internal I/O - USB",
        "Internal I/O - Display",
        "Internal I/O - Audio",
        "Internal I/O - SATA",
        "Internal I/O - NVDS",
        "Internal I/O - DIO",
    ]},
    {"Ports": ["Rear I/O - Ethernet", "Rear I/O - USB", "Rear I/O - Display"]},
    {"Power": [
        "Power - Connector (DC-in Jack, ATX)",
        "Power - Type (DC, ATX) Volts, Ranging",
        "Power - Power Consumption",
    ]},
    {"Environmental": [
        "Temperature - Operating",
        "Temperature - Storage",
        "Humidity - Operating",
        "Humidity - Storage",
        "MTBF",
    ]},
    {"Dimensions & Weight": [
        "Dimensions Length and Width - Millimeters",
        "Dimensions Length and Width - Inches",
        "Dimensions Height",
    ]},
    {"Compliance": [
        "Regulatory Certifications (Example: FCC Class B, CE, UKCA)",
        "Environmental (REACH, ROHS, EU POP, etc.)",
    ]},
    "Others",
]

BOX_PC_KEY_SPECS_ORDER: List[Union[str, Dict[str, List[str]]]] = [
    "Supported Processor",
    "Chipset",
    "RAM (Memory)",
    "BIOS",
    "Graphics Controller",
    "Supported Displays",
    "Expansion Interface",
    "AI Accelerator",
    {"Storage": ["Storage - External", "Storage - Internal"]},
    "Audio",
    "Ethernet – Number of Ports",
    "Ethernet – Controller",
    {"Rear I/O (Key Specs)": ["Rear I/O - Ethernet", "Rear I/O - USB", "Rear I/O - Display"]},
    "LED Indicators",
    {"Front I/O": [
        "Front I/O - Ethernet",
        "Front I/O - Serial",
        "Front I/O - USB",
        "Front I/O - Display",
        "Front I/O - DIO",
        "Front I/O - Power",
        "Front I/O - Audio",
        "Front I/O - Buttons",
    ]},
    {"Rear I/O": [
        "Rear I/O - Ethernet",
        "Rear I/O - Serial",
        "Rear I/O - USB",
        "Rear I/O - Display",
        "Rear I/O - DIO",
        "Rear I/O - Power",
        "Rear I/O - Audio",
        "Rear I/O - Buttons",
        "Rear I/O - Antenna",
        "Rear I/O - SIM",
    ]},
    "Security (TPM)",
    {"Power": [
        "Power - Type (DC, ATX) Volts, Ranging",
        "Power - Connector (DC-in Jack, ATX)",
        "Power - Power Consumption",
    ]},
    "Operating System Support",
    {"Temperature": ["Temperature - Operating", "Temperature - Storage"]},
    {"Humidity": ["Humidity - Operating", "Humidity - Storage"]},
    "MTBF",
    {"Dimensions Length & Width": [
        "Dimensions Length and Width - Millimeters",
        "Dimensions Length and Width - Inches",
    ]},
    "Dimensions Height",
    "Mounting",
    "Material Used",
    "Certifications",
    {"Standards": ["Standards - Shock", "Standards - Vibration", "Standards - IP Rating"]},
    "Country of Origin",
    "Others",
]


#Lookup for per-category ordering
CATEGORY_SPEC_ORDER: Dict[str, List[Union[str, Dict[str, List[str]]]]] = {
    "motherboard": MOTHERBOARD_KEY_SPECS_ORDER,
    "box-pc":     BOX_PC_KEY_SPECS_ORDER,
}