from application.model.configuration import Configurations
from application.repository.api import APIRepository


class UnlockVoucherInteractor(object):
    def __init__(self, configs, api_repository):
        # type: (Configurations, APIRepository) -> None

        self.logger = configs.logger
        self.configs = configs
        self.api_repository = api_repository

    def unlock_benefit(
        self,           # type: UnlockVoucherInteractor
        benefit_id,     # type: str
        pos_id,         # type: int
    ):
        # type: (...) -> None

        try:
            self.logger.info("Unlocking benefitId: {}".format(benefit_id))
            self.api_repository.unlock_benefit(
                benefit_id=benefit_id,
                pos_id=pos_id,
            )
            self.logger.info("Benefit successfully unlocked")
        except Exception as ex:
            self.logger.error("Error at unlock_benefit", exc_info=ex)
            raise ex
