"""Trace la longévité des personnages représentés par les minifigs."""

from pathlib import Path

from lib.plots.minifig_character_spans import plot_character_spans
from lib.rebrickable.minifig_characters import (
    aggregate_character_spans,
    load_minifigs_by_set,
    load_sets_enriched,
    write_character_spans,
)


MINIFIGS_BY_SET_PATH = Path("data/intermediate/minifigs_by_set.csv")
SETS_ENRICHED_PATH = Path("data/intermediate/sets_enriched.csv")
SPANS_PATH = Path("data/intermediate/minifig_character_spans.csv")
DESTINATION_PATH = Path("figures/step24/minifig_character_spans.png")
MILESTONES_PATH = Path("config/milestones.csv")
EXCLUDED_CHARACTERS = ["Figurant"]


def main() -> None:
    """Construit le CSV des bornes et trace le diagramme de longévité."""
    minifigs = load_minifigs_by_set(MINIFIGS_BY_SET_PATH)
    sets_years = load_sets_enriched(SETS_ENRICHED_PATH)
    spans = aggregate_character_spans(minifigs, sets_years, excluded_characters=EXCLUDED_CHARACTERS)
    write_character_spans(SPANS_PATH, spans)
    plot_character_spans(SPANS_PATH, DESTINATION_PATH, milestones_path=MILESTONES_PATH)


if __name__ == "__main__":
    main()
