# -*- coding: utf-8 -*-

from json import JSONEncoder

from application.model.benefit import BenefitList
from typing import Dict, Any


class NDiscountModelJsonEncoder(JSONEncoder):
    def default(self, o):
        instances_dictionary = {
            BenefitList: self._get_benefit_list_json
        }

        if type(o) in instances_dictionary:
            return instances_dictionary[type(o)](o)

        return super(NDiscountModelJsonEncoder, self).default(o)

    @staticmethod
    def _get_benefit_list_json(o):
        # type: (BenefitList) -> Dict[str, Any]

        return {
            "benefitPreTotalSequence": o.benefit_pre_total_sequence,
            "manualBenefitOnTotalSequence": o.manual_benefits_on_total_sequence,
            "discountItemValues": o.discount_item_values,
            "discountIdTipExcluded": o.discount_id_tip_excluded,
            "tenderIdTipExcluded": o.tender_id_tip_excluded,
            "benefitList": o.benefit_list
        }
