from unittest.mock import patch

from edpconfigprovider.parameters import ProviderParameters


class TestProviderParameters:
    def test_builder_parameter_name_with_prefix(self):
        result = ProviderParameters.builder_parameter_name("PREFIX", "NAME")
        assert result == "PREFIX_NAME"

    def test_builder_parameter_name_without_prefix(self):
        result = ProviderParameters.builder_parameter_name(None, "NAME")
        assert result == "NAME"

    def test_builder_parameter_name_multiple_args(self):
        result = ProviderParameters.builder_parameter_name("A", "B", "C")
        assert result == "A_B_C"

    def test_builder_parameter_name_all_none(self):
        result = ProviderParameters.builder_parameter_name(None, None)
        assert result == ""

    def test_get_parameter_with_prefix(self):
        params = ProviderParameters()
        assert params.get_parameter("PARAM", provider_prefix="PREFIX") == "PREFIX_PARAM"

    def test_get_parameter_without_prefix(self):
        params = ProviderParameters()
        assert params.get_parameter("PARAM") == "PARAM"

    def test_get_env_reads_from_environ(self):
        params = ProviderParameters()
        with patch.dict("os.environ", {"MY_PARAM": "value"}):
            assert params.get_env("MY_PARAM") == "value"

    def test_get_env_with_prefix(self):
        params = ProviderParameters()
        with patch.dict("os.environ", {"PREFIX_PARAM": "value"}):
            assert params.get_env("PARAM", provider_prefix="PREFIX") == "value"

    def test_get_env_missing_returns_none(self):
        params = ProviderParameters()
        with patch.dict("os.environ", {}, clear=True):
            assert params.get_env("MISSING_PARAM") is None
