"""Tests für CSV mapping_suggest (Issue #21)."""

from csv_parser.mapping_suggest import (
    build_type_conversions_for_mapping,
    suggest_field_mappings,
)


def test_suggest_from_fddb_seed():
    headers = ["Datum Tag Monat Jahr Stunde Minute", "kJ", "Fett (g)", "KH (g)", "Protein (g)"]
    seed = {
        "datum_tag_monat_jahr_stunde_minute": "date",
        "kj": "kcal",
        "fett_g": "fat_g",
        "kh_g": "carbs_g",
        "protein_g": "protein_g",
    }
    fm = suggest_field_mappings(headers, "nutrition", seed)
    assert fm["Datum Tag Monat Jahr Stunde Minute"] == "date"
    assert fm["kJ"] == "kcal"


def test_suggest_aliases_without_seed():
    fm = suggest_field_mappings(
        ["Date", "Calories", "Protein (g)", "Fat (g)", "Carbs"],
        "nutrition",
        None,
    )
    assert fm["Date"] == "date"
    assert fm["Calories"] == "kcal"
    assert fm["Protein (g)"] == "protein_g"


def test_type_conversions_merge():
    fm = {"Col A": "date", "Col B": "kcal"}
    seed_tc = {
        "kcal": {"type": "float", "conversion_factor": 0.239, "decimal_separator": "auto"},
    }
    tc = build_type_conversions_for_mapping("nutrition", fm, seed_tc)
    assert "kcal" in tc
    assert tc["kcal"].get("conversion_factor") == 0.239
    assert "date" in tc
