# coding: utf-8

"""
    Zuora API Reference

    REST API reference for the Zuora Billing, Payments, and Central Platform! Check out the [REST API Overview](https://www.zuora.com/developer/api-references/api/overview/).

    The version of the OpenAPI document: 2024-05-20
    Contact: docs@zuora.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field
from typing import Any, ClassVar, Dict, List, Optional
from zuora_sdk.models.charge_model_data_override import ChargeModelDataOverride
from zuora_sdk.models.discount_pricing_update import DiscountPricingUpdate
from zuora_sdk.models.recurring_delivery_pricing_update import RecurringDeliveryPricingUpdate
from zuora_sdk.models.recurring_flat_fee_pricing_update import RecurringFlatFeePricingUpdate
from zuora_sdk.models.recurring_per_unit_pricing_update import RecurringPerUnitPricingUpdate
from zuora_sdk.models.recurring_tiered_pricing_update import RecurringTieredPricingUpdate
from zuora_sdk.models.recurring_volume_pricing_update import RecurringVolumePricingUpdate
from zuora_sdk.models.usage_flat_fee_pricing_update import UsageFlatFeePricingUpdate
from zuora_sdk.models.usage_overage_pricing_update import UsageOveragePricingUpdate
from zuora_sdk.models.usage_per_unit_pricing_update import UsagePerUnitPricingUpdate
from zuora_sdk.models.usage_tiered_pricing_update import UsageTieredPricingUpdate
from zuora_sdk.models.usage_tiered_with_overage_pricing_update import UsageTieredWithOveragePricingUpdate
from zuora_sdk.models.usage_volume_pricing_update import UsageVolumePricingUpdate
from typing import Optional, Set
from typing_extensions import Self

class CreateOrderPricingUpdate(BaseModel):
    """
    CreateOrderPricingUpdate
    """ # noqa: E501
    # avoid validation
    def __init__(self, **kwargs):
        # Directly assign values without validation using `construct()`
        model = self.construct(**kwargs)
        self.__dict__.update(model.__dict__)

        _dict_all = convert_snake_dict_to_camel(kwargs, self.model_fields, self.__properties)

        _dict = self.to_alias_dict(_dict_all)
        for field_name, field_info in self.model_fields.items():
            alias = field_info.alias or field_name
            if alias in _dict:
                self.__dict__[field_name] = _dict.get(alias)
        self.update_additional_properties(self, _dict_all)
        pass

    def __setattr__(self, name, value):
        # Override setattr to bypass validation when setting attributes
        object.__setattr__(self, name, value)

    charge_model_data: Optional[ChargeModelDataOverride] = Field(default=None, description="Container for charge model configuration data.  **Note**: This field is only available if you have the High Water Mark, Pre-Rated Pricing, or Multi-Attribute Pricing charge models enabled. The High Water Mark and Pre-Rated Pricing charge models are available for customers with Enterprise and Nine editions by default. If you are a Growth customer, see [Zuora Editions](https://knowledgecenter.zuora.com/BB_Introducing_Z_Business/C_Zuora_Editions) for pricing information. ", alias="chargeModelData")
    discount: Optional[DiscountPricingUpdate] = Field(default=None, description="Pricing information about a discount charge. ")
    recurring_delivery_based: Optional[RecurringDeliveryPricingUpdate] = Field(default=None, description="This field is only available if you have the Delivery Pricing charge model enabled.  **Note**: The Delivery Pricing charge model is in the **Early Adopter** phase. We are actively soliciting feedback from a small set of early adopters before releasing it as generally available. If you want to join this early adopter program, submit a request at <a href=\"http://support.zuora.com/\" target=\"_blank\">Zuora Global Support</a>. ", alias="recurringDeliveryBased")
    recurring_flat_fee: Optional[RecurringFlatFeePricingUpdate] = Field(default=None, description="Pricing information about a recurring charge that uses the \"flat fee\" charge model. In this charge model, the charge has a fixed price. ", alias="recurringFlatFee")
    recurring_per_unit: Optional[RecurringPerUnitPricingUpdate] = Field(default=None, description="Pricing information about a recurring charge that uses the \"per unit\" charge model. In this charge model, the charge has a fixed price per unit purchased. ", alias="recurringPerUnit")
    recurring_tiered: Optional[RecurringTieredPricingUpdate] = Field(default=None, description="Pricing information about a recurring charge that uses the \"tiered pricing\" charge model. In this charge model, the charge has cumulative pricing tiers that become effective as units are purchased. ", alias="recurringTiered")
    recurring_volume: Optional[RecurringVolumePricingUpdate] = Field(default=None, description="Pricing information about a recurring charge that uses the \"volume pricing\" charge model. In this charge model, the charge has a variable price per unit, depending on how many units are purchased. ", alias="recurringVolume")
    usage_flat_fee: Optional[UsageFlatFeePricingUpdate] = Field(default=None, description="Pricing information about a usage charge that uses the \"flat fee\" charge model. In this charge model, the charge has a fixed price. ", alias="usageFlatFee")
    usage_overage: Optional[UsageOveragePricingUpdate] = Field(default=None, description="Pricing information about a usage charge that uses the \"overage\" charge model. In this charge model, the charge has an allowance of free units and a fixed price per additional unit consumed. ", alias="usageOverage")
    usage_per_unit: Optional[UsagePerUnitPricingUpdate] = Field(default=None, description="Pricing information about a usage charge that uses the \"per unit\" charge model. In this charge model, the charge has a fixed price per unit consumed. ", alias="usagePerUnit")
    usage_tiered: Optional[UsageTieredPricingUpdate] = Field(default=None, description="Pricing information about a usage charge that uses the \"tiered pricing\" charge model. In this charge model, the charge has cumulative pricing tiers that become effective as units are consumed. ", alias="usageTiered")
    usage_tiered_with_overage: Optional[UsageTieredWithOveragePricingUpdate] = Field(default=None, description="Pricing information about a usage charge that uses the \"tiered with overage\" charge model. In this charge model, the charge has cumulative pricing tiers that become effective as units are consumed. The charge also has a fixed price per unit consumed beyond the limit of the final tier. ", alias="usageTieredWithOverage")
    usage_volume: Optional[UsageVolumePricingUpdate] = Field(default=None, description="Pricing information about a usage charge that uses the \"volume pricing\" charge model. In this charge model, the charge has a variable price per unit, depending on how many units are consumed. ", alias="usageVolume")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["chargeModelData", "discount", "recurringDeliveryBased", "recurringFlatFee", "recurringPerUnit", "recurringTiered", "recurringVolume", "usageFlatFee", "usageOverage", "usagePerUnit", "usageTiered", "usageTieredWithOverage", "usageVolume"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of CreateOrderPricingUpdate from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of charge_model_data
        if self.charge_model_data:
            _dict['chargeModelData'] = self.charge_model_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of discount
        if self.discount:
            _dict['discount'] = self.discount.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recurring_delivery_based
        if self.recurring_delivery_based:
            _dict['recurringDeliveryBased'] = self.recurring_delivery_based.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recurring_flat_fee
        if self.recurring_flat_fee:
            _dict['recurringFlatFee'] = self.recurring_flat_fee.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recurring_per_unit
        if self.recurring_per_unit:
            _dict['recurringPerUnit'] = self.recurring_per_unit.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recurring_tiered
        if self.recurring_tiered:
            _dict['recurringTiered'] = self.recurring_tiered.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recurring_volume
        if self.recurring_volume:
            _dict['recurringVolume'] = self.recurring_volume.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage_flat_fee
        if self.usage_flat_fee:
            _dict['usageFlatFee'] = self.usage_flat_fee.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage_overage
        if self.usage_overage:
            _dict['usageOverage'] = self.usage_overage.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage_per_unit
        if self.usage_per_unit:
            _dict['usagePerUnit'] = self.usage_per_unit.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage_tiered
        if self.usage_tiered:
            _dict['usageTiered'] = self.usage_tiered.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage_tiered_with_overage
        if self.usage_tiered_with_overage:
            _dict['usageTieredWithOverage'] = self.usage_tiered_with_overage.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage_volume
        if self.usage_volume:
            _dict['usageVolume'] = self.usage_volume.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CreateOrderPricingUpdate from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        obj = convert_snake_dict_to_camel(obj, cls.model_fields, cls.__properties)

        _obj = cls.model_validate(cls.to_alias_dict(obj))
        return cls.update_additional_properties(_obj, obj)

    @classmethod
    def update_additional_properties(cls, obj, _dict: Optional[Dict[str, Any]]):
        # store additional fields in additional_properties

        # store additional fields in additional_properties
        for _key in _dict.keys():
            if _key not in cls.__properties:
                obj.additional_properties[_key] = _dict.get(_key)


        return obj
        pass

    @classmethod
    def to_alias_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]:

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        return {
            "chargeModelData": ChargeModelDataOverride.from_dict(obj["chargeModelData"]) if obj.get("chargeModelData") is not None else None,
            "discount": DiscountPricingUpdate.from_dict(obj["discount"]) if obj.get("discount") is not None else None,
            "recurringDeliveryBased": RecurringDeliveryPricingUpdate.from_dict(obj["recurringDeliveryBased"]) if obj.get("recurringDeliveryBased") is not None else None,
            "recurringFlatFee": RecurringFlatFeePricingUpdate.from_dict(obj["recurringFlatFee"]) if obj.get("recurringFlatFee") is not None else None,
            "recurringPerUnit": RecurringPerUnitPricingUpdate.from_dict(obj["recurringPerUnit"]) if obj.get("recurringPerUnit") is not None else None,
            "recurringTiered": RecurringTieredPricingUpdate.from_dict(obj["recurringTiered"]) if obj.get("recurringTiered") is not None else None,
            "recurringVolume": RecurringVolumePricingUpdate.from_dict(obj["recurringVolume"]) if obj.get("recurringVolume") is not None else None,
            "usageFlatFee": UsageFlatFeePricingUpdate.from_dict(obj["usageFlatFee"]) if obj.get("usageFlatFee") is not None else None,
            "usageOverage": UsageOveragePricingUpdate.from_dict(obj["usageOverage"]) if obj.get("usageOverage") is not None else None,
            "usagePerUnit": UsagePerUnitPricingUpdate.from_dict(obj["usagePerUnit"]) if obj.get("usagePerUnit") is not None else None,
            "usageTiered": UsageTieredPricingUpdate.from_dict(obj["usageTiered"]) if obj.get("usageTiered") is not None else None,
            "usageTieredWithOverage": UsageTieredWithOveragePricingUpdate.from_dict(obj["usageTieredWithOverage"]) if obj.get("usageTieredWithOverage") is not None else None,
            "usageVolume": UsageVolumePricingUpdate.from_dict(obj["usageVolume"]) if obj.get("usageVolume") is not None else None
        }
        return _obj


def convert_snake_dict_to_camel(_dict: dict, model_fields, properties):
    if not isinstance(_dict, dict):
        return _dict
    new_dict = {}
    for k, v in _dict.items():
        if k in model_fields:
            # model_fields: key is attribute name like bill_to_contact,
            alias = model_fields.get(k).alias or k
            new_dict[alias] = v
            pass
        else:
            new_key = snake_to_camel(k)
            if properties is not None and isinstance(properties, list) and new_key in properties:
                new_dict[new_key] = v
            else:
                new_dict[k] = v
    return new_dict
    pass


def snake_to_camel(name):
    if name is None or '_' not in name:
        return name
    components = name.split('_')
    return components[0] + ''.join(x.title() for x in components[1:])
