"""Corner C ingredient parsing, the date-join, and the audio_lens family
classifier (the cpluck-as-perc regression)."""
import build_catalog_view as bcv
import audio_lens as al
from sample_tfidf import sound_vocab


def test_ingredient_sounds_parses_codes():
    vocab, _ = sound_vocab()
    track = {"ingredients": [
        {"type": "sample", "code": 's "[kick:4]"'},
        {"type": "sample", "code": 's "jungle_breaks:84"'},
        {"type": "moment", "code": "highlights"},     # non-sound type → skipped
        {"type": "effect", "code": "d10"},            # effect type → skipped
    ]}
    s = bcv.ingredient_sounds(track, vocab)
    assert "kick" in s and "jungle_breaks" in s
    assert "highlights" not in s


def test_takes_for_gig_exact_fuzzy_and_miss():
    takes = [{"date": "2024-10-01", "take": "Take20", "dur": "", "orbits": 13,
              "type": "SET", "label": ""}]
    exact = bcv.takes_for_gig("2024-10-01", takes)
    assert exact and exact[0][1] == "date-exact"
    fuzzy = bcv.takes_for_gig("2024-10-03", takes)            # within ±3d
    assert fuzzy and "date±2d" in fuzzy[0][1]
    assert bcv.takes_for_gig("2024-11-01", takes) == []       # outside window


def test_classify_family_cpluck_not_perc():
    # the bug that mislabeled cpluck as a drum
    assert al.classify_family("cpluck")[0] != "percs"


def test_classify_family_perc_exact():
    assert al.classify_family("cp")[0] == "percs"
    assert al.classify_family("dr")[0] == "percs"


def test_classify_family_breaks_are_tops():
    assert al.classify_family("jungle_breaks")[0] == "tops"


def test_classify_family_bass_register():
    assert al.classify_family("meth_bass", {"centroid": 100})[0] == "bass"
