import importlib.util
from pathlib import Path


def load_config_class():
    config_path = Path(__file__).resolve().parents[1] / "danding_bot" / "plugins" / "danding_qqpush" / "config.py"
    spec = importlib.util.spec_from_file_location("danding_qqpush_config", config_path)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module.Config


def test_qqpush_config_reads_nonebot_lowercase_token():
    Config = load_config_class()
    config = Config.model_validate({"danding_qqpush_token": "token-from-nonebot"})

    assert config.Token == "token-from-nonebot"


def test_qqpush_config_reads_env_token(monkeypatch):
    Config = load_config_class()
    monkeypatch.setenv("DANDING_QQPUSH_TOKEN", "token-from-env")

    config = Config.model_validate({})

    assert config.Token == "token-from-env"


def test_qqpush_config_has_documented_default_token(monkeypatch):
    Config = load_config_class()
    monkeypatch.delenv("DANDING_QQPUSH_TOKEN", raising=False)

    config = Config.model_validate({})

    assert config.Token == "danding-8HkL9xQ2"
