# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional

import simplejson as json
from application.configurator import Configurator
from application.model import EventData
from application.repository import MessageBusRepository


class StoreStatusInteractor(object):

    def __init__(self, configurations):
        # type: (Configurator) -> None

        self.configs = configurations
        self.logger = self.configs.logger

    def build(self, event_data):
        # type: (EventData) -> Optional[str]

        business_period = event_data.data.get("businessPeriod")
        payload_period = datetime.strptime(business_period, "%Y%m%d")
        timestamp = event_data.timestamp + "Z"

        payload = {
            "type": event_data.type,
            "store-code": str(self.configs.store_id),
            "business-dt": payload_period.strftime("%Y-%m-%d"),
            "event-dttm": timestamp
        }

        return json.dumps(payload)
