from logging import Logger
from typing import Dict

from interactor.route.customization.get_text.dto import GetTextRequest
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 GetTextInteractor(object):

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

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

    def execute(
            self,
            request   # type: GetTextRequest
    ):
        # type: (...) -> Dict

        validate_api_key(request, self.config.api_key_mapping)

        text_by_language = self.pos_repository.get_text_from_i18n()
        if not text_by_language:
            raise ValidationError(PosValidationErrorsType.LanguagesNotFound)

        return text_by_language
