import os
from unittest.mock import patch

from pydantic.types import SecretStr

from local_whisper.settings import WhisperSettings

SETTING_DEFAULTS = {"BASE_ASR_MODEL": "medium.en", "DEFAULT_SAMPLE_RATE": 16000}


def test_setting_defaults():
    """Regression test for settings schema."""
    with patch.dict(os.environ, {}, clear=True):
        savant_settings = WhisperSettings()
        assert len(savant_settings.dict()) == len(SETTING_DEFAULTS)
        for k, v in SETTING_DEFAULTS.items():
            _setting_value = getattr(savant_settings, k.lower())
            unmasked_setting = (
                _setting_value.get_secret_value()
                if isinstance(_setting_value, SecretStr)
                else _setting_value
            )
            unmasked_setting == v


def test_with_envvar_prefix():
    with patch.dict(os.environ, {"WHISPER_DEFAULT_SAMPLE_RATE": "22500"}, clear=True):
        whisper_settings = WhisperSettings()
        assert whisper_settings.default_sample_rate == 22500
