"""#1749 问题 A：变体配音严格守卫测试。"""

import pytest

from packages.domain.variant_voice_resolver import VariantVoiceError, resolve_variant_voice_ids


def test_unified_voice_repeated():
    assert resolve_variant_voice_ids(count=3, voice_library_id="V1") == ["V1", "V1", "V1"]


def test_independent_voices():
    assert resolve_variant_voice_ids(count=3, voice_library_ids=["a", "b", "c"]) == ["a", "b", "c"]


def test_no_voice_returns_empty_strings():
    assert resolve_variant_voice_ids(count=2) == ["", ""]


def test_independent_length_mismatch_raises():
    with pytest.raises(VariantVoiceError):
        resolve_variant_voice_ids(count=3, voice_library_ids=["a", "b"])


def test_independent_missing_value_raises():
    with pytest.raises(VariantVoiceError):
        resolve_variant_voice_ids(count=3, voice_library_ids=["a", "", "c"])


def test_independent_whitespace_missing_raises():
    with pytest.raises(VariantVoiceError):
        resolve_variant_voice_ids(count=2, voice_library_ids=["a", "   "])


def test_count_zero_raises():
    with pytest.raises(VariantVoiceError):
        resolve_variant_voice_ids(count=0)


def test_explicit_multi_does_not_fallback_to_single():
    """传了 voice_library_ids 但长度错 → 400，禁止静默 fallback 到单值。"""
    with pytest.raises(VariantVoiceError):
        resolve_variant_voice_ids(count=3, voice_library_id="SINGLE", voice_library_ids=["x", "y"])


def test_single_voice_with_empty_multi_list():
    assert resolve_variant_voice_ids(count=2, voice_library_id="S", voice_library_ids=[]) == ["S", "S"]


def test_count_one_independent():
    assert resolve_variant_voice_ids(count=1, voice_library_ids=["solo"]) == ["solo"]
