import boto3
import environments
from constants import AWS_RESOURCE_S3, S3_RESPONSE_BODY, UTF8


class S3Resource:

    def __init__(self, bucket_name: str) -> None:
        self.__s3_resource = boto3.resource(AWS_RESOURCE_S3)
        self.__s3_bucket = self.__s3_resource.Bucket(bucket_name)

    def get_object(self, object_key: str):
        s3_object = self.__s3_bucket.Object(object_key)
        response = s3_object.get()
        return response[S3_RESPONSE_BODY].read().decode(UTF8)


class ConfigBucket:
    __s3_resource: S3Resource = None

    def __init__(self) -> None:
        self.__s3_resource = S3Resource(environments.CONFIG_BUCKET_NAME)

    @property
    def check_target_schema_names(self):
        return self.__s3_resource.get_object(environments.CHECK_TARGET_SCHEMA_NAMES_PATH)

    @property
    def notice_mail_title_template(self):
        return self.__s3_resource.get_object(environments.NOTICE_MAIL_TITLE_TEMPLATE_PATH)

    @property
    def notice_mail_body_template(self):
        return self.__s3_resource.get_object(environments.NOTICE_MAIL_BODY_TEMPLATE_PATH)
