import os
from typing import Optional


class ProviderParameters:
    @staticmethod
    def builder_parameter_name(*args):
        return "_".join([arg for arg in args if arg is not None])

    def get_parameter(self, parameter_name: str, provider_prefix: Optional[str] = None):
        return self.builder_parameter_name(provider_prefix, parameter_name)

    def get_env(
        self,
        parameter_name: str,
        provider_prefix: Optional[str] = None,
        default_value: Optional[str] = None
    ) -> Optional[str]:
        return os.environ.get(
            self.get_parameter(
                provider_prefix=provider_prefix,
                parameter_name=parameter_name,
            ),
            default_value
        )

    def get_bool_env(
        self,
        parameter_name: str,
        provider_prefix: Optional[str] = None,
        default_value: Optional[bool] = None
    ):
        ret = self.get_env(
            parameter_name=parameter_name,
            provider_prefix=provider_prefix,
            default_value=str(default_value) if default_value is not None else None,
        )

        if ret is not None:
            return ret.strip().lower() in ("true", "yes", "1")

        return default_value
