"""Couleurs et catégories de pièces à exclure des palettes."""

import csv
from pathlib import Path
from typing import Set


IGNORED_COLOR_RGB = {"0033b2", "05131d"}
IGNORED_PART_CATEGORY_IDS = {
    "1",  # Baseplates
    "8",  # Technic Bricks
    "12",  # Technic Connectors
    "17",  # Gear Parts
    "18",  # Hinges, Arms and Turntables
    "22",  # Pneumatics
    "23",  # Panels
    "25",  # Technic Steering, Suspension and Engine
    "26",  # Technic Special
    "29",  # Wheels and Tyres
    "30",  # Tubes and Hoses
    "31",  # String, Bands and Reels
    "34",  # Supports, Girders and Cranes
    "40",  # Technic Panels
    "43",  # Znap
    "44",  # Mechanical
    "45",  # Electronics
    "46",  # Technic Axles
    "51",  # Technic Beams
    "52",  # Technic Gears
    "53",  # Technic Pins
    "54",  # Technic Bushes
    "55",  # Technic Beams Special
}


def is_ignored_color_rgb(rgb: str) -> bool:
    """Retourne vrai si le code couleur doit être ignoré."""
    return rgb.strip().lower() in IGNORED_COLOR_RGB


def is_ignored_part_category(part_cat_id: str) -> bool:
    """Retourne vrai si la catégorie de pièce est exclue."""
    return part_cat_id.strip() in IGNORED_PART_CATEGORY_IDS


def load_ignored_part_numbers(parts_catalog_path: Path) -> Set[str]:
    """Charge les références de pièces dont la catégorie est exclue."""
    ignored: Set[str] = set()
    with parts_catalog_path.open() as parts_file:
        reader = csv.DictReader(parts_file)
        for row in reader:
            if is_ignored_part_category(row["part_cat_id"]):
                ignored.add(row["part_num"])
    return ignored
