from logging import Logger
from typing import List

from interactor.route.payment.get_payment_types.dto import GetPaymentTypesRequest
from model.config import Config
from model.error_type import PosValidationErrorsType
from model.exception import ValidationError
from model.payment import PaymentType
from model.repository import PosRepositoryModel
from model.services import PaymentServiceModel
from validation_util import validate_api_key


class GetPaymentTypesInteractor(object):

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

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

    def execute(
            self,
            request     # type: GetPaymentTypesRequest
    ):
        # type: (...) -> List[PaymentType]

        validate_api_key(request, self.config.api_key_mapping)

        tender_types = self.payment_service.get_payment_types()

        if not tender_types:
            raise ValidationError(PosValidationErrorsType.PaymentTypesNotFound)

        return tender_types
