from interactor import BaseInteractor
from model.resync import ResyncRequest
from processor import BaseProcessor


class ResyncMessageProcessor(BaseProcessor):
    def __init__(self, interactor):
        # type: (BaseInteractor) -> None
        super(ResyncMessageProcessor, self).__init__()
        self.interactor = interactor

    def parse_data(self, data, event_type):
        params = data.split('\0')

        period = params[0] if params else None
        event_types = params[1] if len(params) > 1 else None
        last_row_id = params[2] if len(params) > 2 else None

        return ResyncRequest(period=period, event_types=event_types, last_row_id=last_row_id)

    def call_business(self, obj):
        self.interactor.execute(obj)
