from application.interactor.apply.service import BenefitApplierService
from application.repository.pos.utils import find_benefit_applier
from .dto.request import ApplyCouponRequest


class ApplyCouponInteractor(object):

    def __init__(
        self,
        benefit_applier_service,        # type: BenefitApplierService
    ):
        # type: (...) -> None

        self.benefit_applier_service = benefit_applier_service

    def apply_coupon(
        self,                  # type: ApplyCouponInteractor
        apply_coupon_request,  # type: ApplyCouponRequest
    ):
        # type: (...) -> None

        benefit_applier = find_benefit_applier(
            pos_id=apply_coupon_request.context.originator_pos_id,
            coupon_id=apply_coupon_request.coupon_id
        )

        self.benefit_applier_service.apply_benefit_by_coupon(
            coupon_id=apply_coupon_request.coupon_id,
            context=apply_coupon_request.context,
            benefit_applier=benefit_applier,
        )
