"""Trace la corrélation entre nombre de pièces et nombre de minifigs par set."""

from pathlib import Path

from lib.plots.minifig_parts_correlation import plot_minifig_parts_correlation
from lib.plots.minifig_parts_timeline import plot_minifigs_per_set_timeline
from lib.rebrickable.minifig_parts_correlation import (
    build_correlation_rows,
    build_minifigs_per_year,
    write_correlation_rows,
    write_minifigs_per_year,
)


FILTERED_MINIFIG_COUNTS_PATH = Path("data/intermediate/minifig_counts_by_set.csv")
FILTERED_SETS_PATH = Path("data/intermediate/sets_enriched.csv")
ALL_SETS_PATH = Path("data/raw/sets.csv")
INVENTORIES_PATH = Path("data/raw/inventories.csv")
INVENTORY_MINIFIGS_PATH = Path("data/raw/inventory_minifigs.csv")
CORRELATION_PATH = Path("data/intermediate/minifig_parts_correlation.csv")
MINIFIGS_PER_YEAR_PATH = Path("data/intermediate/minifigs_per_set_timeline.csv")
DESTINATION_PATH = Path("figures/step26/minifig_parts_correlation.png")
TIMELINE_DESTINATION_PATH = Path("figures/step26/minifigs_per_set_timeline.png")


def main() -> None:
    """Construit le CSV de corrélation et trace le diagramme comparatif."""
    rows = build_correlation_rows(
        FILTERED_MINIFIG_COUNTS_PATH,
        FILTERED_SETS_PATH,
        ALL_SETS_PATH,
        INVENTORIES_PATH,
        INVENTORY_MINIFIGS_PATH,
    )
    write_correlation_rows(CORRELATION_PATH, rows)
    plot_minifig_parts_correlation(CORRELATION_PATH, DESTINATION_PATH)
    per_year = build_minifigs_per_year(
        FILTERED_MINIFIG_COUNTS_PATH,
        ALL_SETS_PATH,
        INVENTORIES_PATH,
        INVENTORY_MINIFIGS_PATH,
    )
    write_minifigs_per_year(MINIFIGS_PER_YEAR_PATH, per_year)
    plot_minifigs_per_set_timeline(MINIFIGS_PER_YEAR_PATH, TIMELINE_DESTINATION_PATH)


if __name__ == "__main__":
    main()
