"""Analyse des couleurs de têtes de minifigs."""

from pathlib import Path

from lib.rebrickable.colors_by_set import build_colors_lookup
from lib.rebrickable.minifig_heads import (
    aggregate_head_colors_by_set,
    aggregate_head_colors_by_year,
    build_head_part_set,
    load_parts_filtered,
    write_head_colors_by_set,
    write_head_colors_by_year,
)


PARTS_FILTERED_PATH = Path("data/intermediate/parts_filtered.csv")
PARTS_CATALOG_PATH = Path("data/raw/parts.csv")
COLORS_PATH = Path("data/raw/colors.csv")
HEADS_BY_SET_PATH = Path("data/intermediate/minifig_heads_by_set.csv")
HEADS_BY_YEAR_PATH = Path("data/intermediate/minifig_heads_by_year.csv")


def main() -> None:
    """Construit les agrégats des couleurs de têtes."""
    parts_rows = load_parts_filtered(PARTS_FILTERED_PATH)
    head_parts = build_head_part_set(PARTS_CATALOG_PATH)
    colors_lookup = build_colors_lookup(COLORS_PATH)
    heads_by_set = aggregate_head_colors_by_set(parts_rows, head_parts, colors_lookup)
    heads_by_year = aggregate_head_colors_by_year(heads_by_set)
    write_head_colors_by_set(HEADS_BY_SET_PATH, heads_by_set)
    write_head_colors_by_year(HEADS_BY_YEAR_PATH, heads_by_year)


if __name__ == "__main__":
    main()
