import json
from datetime import datetime

from typing import Dict

from interactor.event import EventInteractor
from model.log import LogEntry
from processor.event import EventProcessor


def _get_log_entry_from_pos_event(
        data,       # type: str
        event_type  # type: Dict
):
    json_data = json.loads(data)
    created_at = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
    business_period = datetime.utcnow().strftime("%Y%m%d")
    return LogEntry(
            pos_id=json_data.get("pos_id", None),
            business_period=business_period,
            event_type=event_type,
            created_at_gmt=created_at,
            event_data=data
    )


class PosUpdaterEventProcessor(
        EventProcessor  # type: EventInteractor
):

    def parse_data(self, data, event_type):
        return _get_log_entry_from_pos_event(data, event_type)



