"""Ajoute le total de minifigs aux statistiques principales."""

from pathlib import Path

from lib.rebrickable.minifig_stats import compute_filtered_minifig_total, merge_minifig_stat
from lib.rebrickable.stats import compute_basic_stats, read_rows, write_stats_csv


THEMES_PATH = Path("data/raw/themes.csv")
ALL_SETS_PATH = Path("data/raw/sets.csv")
FILTERED_SETS_PATH = Path("data/intermediate/sets_filtered.csv")
ENRICHED_SETS_PATH = Path("data/intermediate/sets_enriched.csv")
INVENTORIES_PATH = Path("data/raw/inventories.csv")
INVENTORY_MINIFIGS_PATH = Path("data/raw/inventory_minifigs.csv")
DESTINATION_PATH = Path("data/final/stats.csv")


def main() -> None:
    """Recalcule les statistiques de base et ajoute le total de minifigs."""
    themes = read_rows(THEMES_PATH)
    all_sets = read_rows(ALL_SETS_PATH)
    filtered_sets = read_rows(FILTERED_SETS_PATH)
    enriched_sets = read_rows(ENRICHED_SETS_PATH)
    base_stats = compute_basic_stats(themes, all_sets, filtered_sets, enriched_sets)
    minifig_total = compute_filtered_minifig_total(filtered_sets, INVENTORIES_PATH, INVENTORY_MINIFIGS_PATH)
    stats = merge_minifig_stat(base_stats, minifig_total)
    write_stats_csv(DESTINATION_PATH, stats)


if __name__ == "__main__":
    main()
