from logging import Logger

from interactor.route.peripheral.print_text.dto import PrintTextRequest
from model.config import Config
from model.error_type import PosValidationErrorsType
from model.exception import ValidationError
from model.repository import PosRepositoryModel
from validation_util import validate_api_key


class PrintTextInteractor(object):
    def __init__(self, logger, config, pos_repository):
        # type: (Logger, Config, PosRepositoryModel) -> None

        self.logger = logger
        self.config = config
        self.pos_repository = pos_repository

    def execute(self, request):
        # type: (PrintTextRequest) -> None

        pos_id = validate_api_key(request, self.config.api_key_mapping)
        if not pos_id:
            raise ValidationError(PosValidationErrorsType.PosIdNotFound)

        self.pos_repository.print_text(pos_id, request.content)
