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

"""
    ontraportlib.models.offer
 
    This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) on 11/14/2017
"""
import  ontraportlib.models.product
import  ontraportlib.models.tax
import  ontraportlib.models.base_model

class Offer(ontraportlib.models.base_model.BaseModel):

    """Implementation of the 'Offer' model.

    TODO: type model description here.

    Attributes:
        offer_id (int): This must be a valid Offer ID.
        order_id (int): This must be a valid Order ID.
        products (list of Product): TODO: type description here.
        cc_expiration_date (string): Credit card expiration date.
        delay (int): Days to delay start of offer.
        grand_total (float): Total amount of sale.
        has_shipping (bool): Are there shipping charges?
        has_taxes (bool): Are there applicable taxes?
        shipping (float): Shipping amount.
        shipping_charge_reoccurring_orders (bool): Add shipping charge to
            reoccurring orders?
        sub_total (float): Subtotal.
        taxes (list of Tax): TODO: type description here.

    """

    def __init__(self, 
                 offer_id = None,
                 order_id = None,
                 products = None,
                 cc_expiration_date = None,
                 delay = None,
                 grand_total = None,
                 has_shipping = False,
                 has_taxes = False,
                 shipping = None,
                 shipping_charge_reoccurring_orders = False,
                 sub_total = None,
                 taxes = None):
        """Constructor for the Offer class"""
        
        # Initialize members of the class
        self.offer_id = offer_id
        self.order_id = order_id
        self.products = products
        self.cc_expiration_date = cc_expiration_date
        self.delay = delay
        self.grand_total = grand_total
        self.has_shipping = has_shipping
        self.has_taxes = has_taxes
        self.shipping = shipping
        self.shipping_charge_reoccurring_orders = shipping_charge_reoccurring_orders
        self.sub_total = sub_total
        self.taxes = taxes

        # Create a mapping from Model property names to API property names
        self.names = {
            "offer_id" : "offer_id",
            "order_id" : "order_id",
            "products" : "products",
            "cc_expiration_date" : "ccExpirationDate",
            "delay" : "delay",
            "grand_total" : "grandTotal",
            "has_shipping" : "hasShipping",
            "has_taxes" : "hasTaxes",
            "shipping" : "shipping",
            "shipping_charge_reoccurring_orders" : "shipping_charge_reoccurring_orders",
            "sub_total" : "subTotal",
            "taxes" : "taxes",
        }


    @classmethod
    def from_dictionary(cls, 
                        dictionary):
        """Creates an instance of this model from a dictionary
       
        Args:
            dictionary (dictionary): A dictionary representation of the object as
            obtained from the deserialization of the server's response. The keys
            MUST match property names in the API description.
            
        Returns:
            object: An instance of this structure class.
            
        """
        if dictionary == None:
            return None
        else:
            # Extract variables from the dictionary
            offer_id = dictionary.get("offer_id")
            order_id = dictionary.get("order_id")
            products = None
            if dictionary.get("products") != None:
                products = list()
                for structure in dictionary.get("products"):
                    products.append(ontraportlib.models.product.Product.from_dictionary(structure))
            cc_expiration_date = dictionary.get("ccExpirationDate")
            delay = dictionary.get("delay")
            grand_total = dictionary.get("grandTotal")
            has_shipping = dictionary.get("hasShipping") if dictionary.get("hasShipping") else False
            has_taxes = dictionary.get("hasTaxes") if dictionary.get("hasTaxes") else False
            shipping = dictionary.get("shipping")
            shipping_charge_reoccurring_orders = dictionary.get("shipping_charge_reoccurring_orders") if dictionary.get("shipping_charge_reoccurring_orders") else False
            sub_total = dictionary.get("subTotal")
            taxes = None
            if dictionary.get("taxes") != None:
                taxes = list()
                for structure in dictionary.get("taxes"):
                    taxes.append(ontraportlib.models.tax.Tax.from_dictionary(structure))
            # Return an object of this model
            return cls(offer_id,
                       order_id,
                       products,
                       cc_expiration_date,
                       delay,
                       grand_total,
                       has_shipping,
                       has_taxes,
                       shipping,
                       shipping_charge_reoccurring_orders,
                       sub_total,
                       taxes)
