"""Trace la présence annuelle des personnages représentés par les minifigs (hors figurants)."""

from pathlib import Path

from lib.plots.minifig_characters import plot_character_year_presence
from lib.rebrickable.minifig_characters import (
    aggregate_presence_by_year,
    load_minifigs_by_set,
    load_sets_enriched,
    write_presence_by_year,
)


MINIFIGS_BY_SET_PATH = Path("data/intermediate/minifigs_by_set.csv")
SETS_ENRICHED_PATH = Path("data/intermediate/sets_enriched.csv")
PRESENCE_PATH = Path("data/intermediate/minifig_characters_year_presence.csv")
DESTINATION_PATH = Path("figures/step23/minifig_characters_timeline.png")
EXCLUDED_CHARACTERS = ["Figurant"]


def main() -> None:
    """Construit le total par année et trace la heatmap."""
    minifigs = load_minifigs_by_set(MINIFIGS_BY_SET_PATH)
    sets_years = load_sets_enriched(SETS_ENRICHED_PATH)
    presence = aggregate_presence_by_year(minifigs, sets_years, excluded_characters=EXCLUDED_CHARACTERS)
    write_presence_by_year(PRESENCE_PATH, presence)
    plot_character_year_presence(PRESENCE_PATH, DESTINATION_PATH)


if __name__ == "__main__":
    main()
