# pylint: disable=too-few-public-methods

"""
    CUSTOM WRITER CLASSES
"""
import os
from datetime import datetime

import boto3


class CustomS3JsonWriter:
    """Class Extends Basic LocalGZJsonWriter"""

    def __init__(self, bucket, file_path, profile_name=None):
        self.bucket = bucket
        self.file_path = file_path

        self.profile_name = profile_name

        if profile_name is None:
            self.boto3_session = boto3.Session()
        else:
            self.boto3_session = boto3.Session(profile_name=profile_name)

        self.s3_resource = self.boto3_session.resource('s3')

    def write_to_s3(self, data, extension):
        """
            Writes json data to s3 and names it by
            date of writing.
        """
        if extension not in ['json', 'csv', 'json.gz', 'csv.gz']:
            raise ValueError(f'Param: {extension} is not a '
                             f'valid option for extension.')

        now = datetime.now().strftime('%Y_%m_%d_%H%M%S')
        key_path = f'{os.path.join(self.file_path, now)}.{extension}'

        self.s3_resource.Object(self.bucket, key_path) \
            .put(Body=data)
