"""BGM混音单元测试 - 配置解析等纯逻辑."""

from __future__ import annotations

import pytest
from video_processing.bgm_mixer import BGMConfig


class TestBGMConfigDefaults:
    """BGMConfig 默认值测试."""

    def test_default_values(self):
        """默认值正确."""
        config = BGMConfig(bgm_path="/bgm.mp3")
        assert config.bgm_path == "/bgm.mp3"
        assert config.volume == 0.3
        assert config.fade_in == 0.0
        assert config.fade_out == 0.0
        assert config.loop_enabled is True
        assert config.sidechain_enabled is False
        assert config.sidechain_ratio == 0.3
        assert config.sidechain_attack == 0.02
        assert config.sidechain_release == 0.5
        assert config.sidechain_threshold == -25.0


class TestBGMConfigFromConfigDict:
    """BGMConfig.from_config_dict 解析测试."""

    def test_empty_dict_defaults(self):
        """空字典用默认值."""
        config = BGMConfig.from_config_dict("/bgm.mp3", {})
        assert config.bgm_path == "/bgm.mp3"
        assert config.volume == 0.3
        assert config.loop_enabled is True
        assert config.sidechain_enabled is False

    def test_custom_volume(self):
        """自定义音量."""
        config = BGMConfig.from_config_dict("/a.mp3", {"volume": 0.5})
        assert config.volume == 0.5

    def test_fade_in_out(self):
        """淡入淡出."""
        config = BGMConfig.from_config_dict(
            "/a.mp3",
            {
                "fade_in": 2.0,
                "fade_out": 3.0,
            },
        )
        assert config.fade_in == 2.0
        assert config.fade_out == 3.0

    def test_loop_disabled(self):
        """禁用循环."""
        config = BGMConfig.from_config_dict("/a.mp3", {"loop_enabled": False})
        assert config.loop_enabled is False

    def test_sidechain_enabled(self):
        """启用人声闪避."""
        config = BGMConfig.from_config_dict("/a.mp3", {"sidechain_enabled": True})
        assert config.sidechain_enabled is True

    def test_sidechain_custom_params(self):
        """闪避自定义参数."""
        config = BGMConfig.from_config_dict(
            "/a.mp3",
            {
                "sidechain_enabled": True,
                "sidechain_ratio": 0.5,
                "sidechain_attack": 0.05,
                "sidechain_release": 0.8,
                "sidechain_threshold": -30.0,
            },
        )
        assert config.sidechain_ratio == 0.5
        assert config.sidechain_attack == 0.05
        assert config.sidechain_release == 0.8
        assert config.sidechain_threshold == -30.0

    def test_bgm_path_preserved(self):
        """bgm_path保持不变."""
        config = BGMConfig.from_config_dict("/custom/path.mp3", {"volume": 0.5})
        assert config.bgm_path == "/custom/path.mp3"

    def test_all_params_custom(self):
        """所有参数自定义."""
        config = BGMConfig.from_config_dict(
            "/full.mp3",
            {
                "volume": 0.7,
                "fade_in": 1.5,
                "fade_out": 2.0,
                "loop_enabled": False,
                "sidechain_enabled": True,
                "sidechain_ratio": 0.4,
                "sidechain_attack": 0.03,
                "sidechain_release": 0.6,
                "sidechain_threshold": -20.0,
            },
        )
        assert config.volume == 0.7
        assert config.fade_in == 1.5
        assert config.fade_out == 2.0
        assert config.loop_enabled is False
        assert config.sidechain_enabled is True
        assert config.sidechain_ratio == 0.4
        assert config.sidechain_attack == 0.03
        assert config.sidechain_release == 0.6
        assert config.sidechain_threshold == -20.0
