"""Unit tests for the pure Visual×Audio resolver (audio spec §4/§6)."""
import pytest

from player.audio import (
    AUDIO_SOURCES,
    VISUAL_POSITIONS,
    AudioResolution,
    resolve_audio,
    resolve_audio_url,
    resolve_visual,
)

def test_visual_on_off():
    assert resolve_visual("on") is True
    assert resolve_visual("off") is False


def test_visual_rejects_unknown():
    with pytest.raises(ValueError):
        resolve_visual("flicker")


def test_visual_positions_are_on_off():
    assert VISUAL_POSITIONS == frozenset({"on", "off"})


def test_audio_sources_are_off_and_soundtrack():
    assert AUDIO_SOURCES == frozenset({"off", "soundtrack"})


def test_soundtrack_resolves_to_the_current_scales_asset():
    url = resolve_audio_url("soundtrack", scale_audio="coast/waves.loop.mp3")
    assert url == "/media/audio/coast/waves.loop.mp3"


def test_off_resolves_to_silence():
    assert resolve_audio_url("off", scale_audio="coast/waves.loop.mp3") is None


def test_soundtrack_with_no_scale_asset_is_silent():
    assert resolve_audio_url("soundtrack", scale_audio="") is None


def test_resolve_audio_marks_only_soundtrack_altitude_coupled():
    r = resolve_audio("soundtrack", scale_audio="reef/soundscape.loop.mp3")
    assert isinstance(r, AudioResolution)
    assert r.source == "soundtrack" and r.altitude_coupled is True
    assert r.url == "/media/audio/reef/soundscape.loop.mp3"
    assert resolve_audio("off", scale_audio="x/y.mp3").altitude_coupled is False


def test_resolve_audio_url_rejects_unknown_source():
    with pytest.raises(ValueError):
        resolve_audio_url("white_noise", scale_audio="")   # deferred, not a v1 source


def test_music_and_white_noise_are_not_v1_sources():
    assert "music" not in AUDIO_SOURCES
    assert "white_noise" not in AUDIO_SOURCES
