import logging

from .dto import LockBenefitRequest
from application.repository.api import APIRepository

logger = logging.getLogger(__name__)


class LockBenefitInteractor(object):
    def __init__(
        self,            # type: LockBenefitInteractor
        api_repository,  # type: APIRepository
    ):
        # type: (...) -> None

        self.api_repository = api_repository

    def lock_benefit(
        self,       # type: LockBenefitInteractor
        request,    # type: LockBenefitRequest
    ):
        # type: (...) -> str

        logger.info("Locking benefit: {}; PosId: {}".format(request.benefit.get("id"), request.pos_id))
        lock_id = self.api_repository.lock_benefit(
            benefit=request.benefit,
            pos_id=request.pos_id,
            payment_info=request.payment_info,
        )
        message = "Benefit {}; PosId: {} locked with lock id: {}"
        logger.info(message.format(request.benefit.get("id"), request.pos_id, lock_id))
        return lock_id
