from typing import List, Dict


class ActionResult(object):
    def __init__(self, discounts_id, items_to_burn, order_tender_ids, discount_item_values, benefit_applied,
                 pending_to_apply):
        # type: (List, Dict, List, Dict, bool, bool) -> None

        self.discounts_id = discounts_id
        self.items_to_burn = items_to_burn
        self.order_tenders = order_tender_ids
        self.discount_item_values = discount_item_values
        self.benefit_applied = benefit_applied
        self.pending_to_apply = pending_to_apply

    def __add__(self, action_result):
        # type: (ActionResult) -> ActionResult

        return self._merge_action_result(self, action_result)

    def __radd__(self, action_result):
        # type: (ActionResult) -> ActionResult

        return self._merge_action_result(self, action_result)

    def __nonzero__(self):
        # type: () -> bool
        return bool(self.discounts_id) or bool(self.items_to_burn) or bool(self.order_tenders) or self.pending_to_apply

    @staticmethod
    def _merge_action_result(current, new):
        current.discounts_id.extend(new.discounts_id)
        current.order_tenders.extend(new.order_tenders)
        current.discount_item_values.update(new.discount_item_values)
        current.benefit_applied = current.benefit_applied and new.benefit_applied
        current.pending_to_apply = current.pending_to_apply or new.pending_to_apply

        return ActionResult(current.discounts_id, current.items_to_burn, current.order_tenders,
                            current.discount_item_values, current.benefit_applied, current.pending_to_apply)

