from edpconfigprovider import ConfigProvider
from edpconfigprovider.parameters import ProviderParameters

AWS_APPCONFIG_PREFIX = "AWS_APPCONFIG"
AWS_SSM_PREFIX = "AWS_SSM"


def build_appconfig_config_provider(parameters: ProviderParameters) -> ConfigProvider:
    from ..appconfig import AwsAppconfigProvider

    return AwsAppconfigProvider(
        application_name=parameters.get_env(parameter_name="APPLICATION_NAME", provider_prefix=AWS_APPCONFIG_PREFIX),
        profile_name=parameters.get_env(parameter_name="PROFILE_NAME", provider_prefix=AWS_APPCONFIG_PREFIX),
        environment_name=parameters.get_env(parameter_name="ENVIRONMENT_NAME", provider_prefix=AWS_APPCONFIG_PREFIX),
    )


def build_appconfig_agent_config_provider(parameters: ProviderParameters) -> ConfigProvider:
    from ..appconfig import AwsAppconfigAgentProvider

    return AwsAppconfigAgentProvider(
        application_name=parameters.get_env(parameter_name="APPLICATION_NAME", provider_prefix=AWS_APPCONFIG_PREFIX),
        profile_name=parameters.get_env(parameter_name="PROFILE_NAME", provider_prefix=AWS_APPCONFIG_PREFIX),
        environment_name=parameters.get_env(parameter_name="ENVIRONMENT_NAME", provider_prefix=AWS_APPCONFIG_PREFIX),
    )


def build_ssm_config_provider(parameters: ProviderParameters) -> ConfigProvider:
    from ..ssm import AwsSsmProvider

    return AwsSsmProvider(
        parameter_path=parameters.get_env(parameter_name="PARAMETER_PATH", provider_prefix=AWS_SSM_PREFIX),
        recursive=parameters.get_bool_env(
            parameter_name="RECURSIVE",
            provider_prefix=AWS_SSM_PREFIX,
            default_value=True
        ),
        split_path=parameters.get_bool_env(
            parameter_name="SPLIT_PATH",
            provider_prefix=AWS_SSM_PREFIX,
            default_value=True
        ),
        decrypt=parameters.get_bool_env(
            parameter_name="DECRYPT",
            provider_prefix=AWS_SSM_PREFIX,
            default_value=True
        ),
    )
