from xml.etree import cElementTree as eTree

from application.model import DefaultBenefitApplierRepository, BenefitAppliers
from application.model.configuration import Configurations
from application.repository.pos import DBRepository
from application.repository.pos.utils import find_order_benefits_id
from typing import Dict


class OrderModifiedReopenedInteractor(object):
    
    def __init__(self, configs, db_repository, benefit_appliers_repositories):
        # type: (Configurations, DBRepository, Dict[BenefitAppliers: DefaultBenefitApplierRepository]) -> None
        
        self.configs = configs
        self.logger = self.configs.logger
        self.db_repository = db_repository
        self.benefit_appliers_repositories = benefit_appliers_repositories

    def remove_benefit(self, current_pos_id, originator_pos_id, order_id, order_picture):
        # type: (int, int, int, eTree) -> None

        order_benefits_id = find_order_benefits_id(self.logger, order_picture)
        if not order_benefits_id:
            return

        message = "Benefits founded to remove: {}; Current/Originator PosId: {}/{}; OrderId: {}"
        self.logger.info(message.format(order_benefits_id, current_pos_id, originator_pos_id, order_id))
        
        self.benefit_appliers_repositories[BenefitAppliers.N_DISCOUNT].remove_benefit(current_pos_id)
