import boto3
import environments
from constants import (AWS_RESOURCE_SSM, SSM_PARAMETER_RESPONSE,
                       SSM_PARAMETER_VALUE)


class SSMClient:

    def __init__(self) -> None:
        self.__ssm_client = boto3.client(AWS_RESOURCE_SSM)

    def get_ssm_params(self, parameter_key: str, with_decryption: bool):
        response = self.__ssm_client.get_parameter(Name=parameter_key, WithDecryption=with_decryption)
        parameter_value = response[SSM_PARAMETER_RESPONSE][SSM_PARAMETER_VALUE]
        return parameter_value


class SSMParameterStore:
    __ssm_client: SSMClient = None

    def __init__(self) -> None:
        self.__ssm_client = SSMClient()

    @property
    def db_host(self):
        return self.__ssm_client.get_ssm_params(environments.PARAM_NAME_DB_HOST, True)

    @property
    def db_user_name(self):
        return self.__ssm_client.get_ssm_params(environments.PARAM_NAME_DB_USER_NAME, True)

    @property
    def db_user_password(self):
        return self.__ssm_client.get_ssm_params(environments.PARAM_NAME_DB_USER_PASSWORD, True)
