# encoding: utf-8

from typing import Dict


class OrderBenefitInfo(object):
    def __init__(self, benefit,
                 discount_item_values,
                 order_state,
                 benefit_key,
                 promotion_tender,
                 burnt_items,
                 benefit_total_value):
        # type: (Dict, Dict, str, str, Dict, Dict, float) -> None

        self.benefit = benefit
        self.order_state = order_state
        self.discount_item_values = discount_item_values
        self.benefit_key = benefit_key
        self.burnt_items = burnt_items
        self.promotion_tender = promotion_tender
        self.benefit_total_value = benefit_total_value
        self.benefit_name = self.benefit.get("name", "").encode("utf8")
        self.benefit_description = self.benefit.get("userDescription", "").encode("utf8")

    @staticmethod
    def from_json(json):
        # type: (Dict) -> OrderBenefitInfo

        benefit = json.get("benefit", {})
        order_state = json.get("order_state")
        item_values = json.get("discount_item_values", {})
        benefit_key = json.get("benefit_key", None)
        burnt_items = json.get("burnt_items", {})
        promotion_tender = json.get("promotion_tender", [])
        benefit_total_value = json.get("benefit_total_value", 0.0)

        return OrderBenefitInfo(benefit,
                                item_values,
                                order_state,
                                benefit_key,
                                promotion_tender,
                                burnt_items,
                                benefit_total_value)
