"""Trace le nombre de minifigs distinctes par personnage."""

from pathlib import Path

from lib.plots.minifig_characters import plot_minifigs_per_character
from lib.rebrickable.minifig_characters import aggregate_by_character, load_minifigs_by_set, write_character_counts


MINIFIGS_BY_SET_PATH = Path("data/intermediate/minifigs_by_set.csv")
COUNTS_PATH = Path("data/intermediate/minifig_characters_counts.csv")
DESTINATION_PATH = Path("figures/step22/minifig_characters.png")


def main() -> None:
    """Construit le CSV de comptage par personnage et trace le graphique."""
    rows = load_minifigs_by_set(MINIFIGS_BY_SET_PATH)
    aggregates = aggregate_by_character(rows)
    write_character_counts(COUNTS_PATH, aggregates)
    plot_minifigs_per_character(COUNTS_PATH, DESTINATION_PATH)


if __name__ == "__main__":
    main()
