# 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_override import DiscountPricingOverride
from zuora_sdk.models.one_time_flat_fee_pricing_override import OneTimeFlatFeePricingOverride
from zuora_sdk.models.one_time_per_unit_pricing_override import OneTimePerUnitPricingOverride
from zuora_sdk.models.one_time_tiered_pricing_override import OneTimeTieredPricingOverride
from zuora_sdk.models.one_time_volume_pricing_override import OneTimeVolumePricingOverride
from zuora_sdk.models.recurring_delivery_pricing_override import RecurringDeliveryPricingOverride
from zuora_sdk.models.recurring_flat_fee_pricing_override import RecurringFlatFeePricingOverride
from zuora_sdk.models.recurring_per_unit_pricing_override import RecurringPerUnitPricingOverride
from zuora_sdk.models.recurring_tiered_pricing_override import RecurringTieredPricingOverride
from zuora_sdk.models.recurring_volume_pricing_override import RecurringVolumePricingOverride
from zuora_sdk.models.usage_flat_fee_pricing_override import UsageFlatFeePricingOverride
from zuora_sdk.models.usage_overage_pricing_override import UsageOveragePricingOverride
from zuora_sdk.models.usage_per_unit_pricing_override import UsagePerUnitPricingOverride
from zuora_sdk.models.usage_tiered_pricing_override import UsageTieredPricingOverride
from zuora_sdk.models.usage_tiered_with_overage_pricing_override import UsageTieredWithOveragePricingOverride
from zuora_sdk.models.usage_volume_pricing_override import UsageVolumePricingOverride
from typing import Optional, Set
from typing_extensions import Self

class ChargeOverridePricing(BaseModel):
    """
    Pricing information about the charge. 
    """ # 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, alias="chargeModelData")
    discount: Optional[DiscountPricingOverride] = None
    one_time_flat_fee: Optional[OneTimeFlatFeePricingOverride] = Field(default=None, alias="oneTimeFlatFee")
    one_time_per_unit: Optional[OneTimePerUnitPricingOverride] = Field(default=None, alias="oneTimePerUnit")
    one_time_tiered: Optional[OneTimeTieredPricingOverride] = Field(default=None, alias="oneTimeTiered")
    one_time_volume: Optional[OneTimeVolumePricingOverride] = Field(default=None, alias="oneTimeVolume")
    recurring_delivery: Optional[RecurringDeliveryPricingOverride] = Field(default=None, alias="recurringDelivery")
    recurring_flat_fee: Optional[RecurringFlatFeePricingOverride] = Field(default=None, alias="recurringFlatFee")
    recurring_per_unit: Optional[RecurringPerUnitPricingOverride] = Field(default=None, alias="recurringPerUnit")
    recurring_tiered: Optional[RecurringTieredPricingOverride] = Field(default=None, alias="recurringTiered")
    recurring_volume: Optional[RecurringVolumePricingOverride] = Field(default=None, alias="recurringVolume")
    usage_flat_fee: Optional[UsageFlatFeePricingOverride] = Field(default=None, alias="usageFlatFee")
    usage_overage: Optional[UsageOveragePricingOverride] = Field(default=None, alias="usageOverage")
    usage_per_unit: Optional[UsagePerUnitPricingOverride] = Field(default=None, alias="usagePerUnit")
    usage_tiered: Optional[UsageTieredPricingOverride] = Field(default=None, alias="usageTiered")
    usage_tiered_with_overage: Optional[UsageTieredWithOveragePricingOverride] = Field(default=None, alias="usageTieredWithOverage")
    usage_volume: Optional[UsageVolumePricingOverride] = Field(default=None, alias="usageVolume")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["chargeModelData", "discount", "oneTimeFlatFee", "oneTimePerUnit", "oneTimeTiered", "oneTimeVolume", "recurringDelivery", "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 ChargeOverridePricing 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 one_time_flat_fee
        if self.one_time_flat_fee:
            _dict['oneTimeFlatFee'] = self.one_time_flat_fee.to_dict()
        # override the default output from pydantic by calling `to_dict()` of one_time_per_unit
        if self.one_time_per_unit:
            _dict['oneTimePerUnit'] = self.one_time_per_unit.to_dict()
        # override the default output from pydantic by calling `to_dict()` of one_time_tiered
        if self.one_time_tiered:
            _dict['oneTimeTiered'] = self.one_time_tiered.to_dict()
        # override the default output from pydantic by calling `to_dict()` of one_time_volume
        if self.one_time_volume:
            _dict['oneTimeVolume'] = self.one_time_volume.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recurring_delivery
        if self.recurring_delivery:
            _dict['recurringDelivery'] = self.recurring_delivery.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 ChargeOverridePricing 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": DiscountPricingOverride.from_dict(obj["discount"]) if obj.get("discount") is not None else None,
            "oneTimeFlatFee": OneTimeFlatFeePricingOverride.from_dict(obj["oneTimeFlatFee"]) if obj.get("oneTimeFlatFee") is not None else None,
            "oneTimePerUnit": OneTimePerUnitPricingOverride.from_dict(obj["oneTimePerUnit"]) if obj.get("oneTimePerUnit") is not None else None,
            "oneTimeTiered": OneTimeTieredPricingOverride.from_dict(obj["oneTimeTiered"]) if obj.get("oneTimeTiered") is not None else None,
            "oneTimeVolume": OneTimeVolumePricingOverride.from_dict(obj["oneTimeVolume"]) if obj.get("oneTimeVolume") is not None else None,
            "recurringDelivery": RecurringDeliveryPricingOverride.from_dict(obj["recurringDelivery"]) if obj.get("recurringDelivery") is not None else None,
            "recurringFlatFee": RecurringFlatFeePricingOverride.from_dict(obj["recurringFlatFee"]) if obj.get("recurringFlatFee") is not None else None,
            "recurringPerUnit": RecurringPerUnitPricingOverride.from_dict(obj["recurringPerUnit"]) if obj.get("recurringPerUnit") is not None else None,
            "recurringTiered": RecurringTieredPricingOverride.from_dict(obj["recurringTiered"]) if obj.get("recurringTiered") is not None else None,
            "recurringVolume": RecurringVolumePricingOverride.from_dict(obj["recurringVolume"]) if obj.get("recurringVolume") is not None else None,
            "usageFlatFee": UsageFlatFeePricingOverride.from_dict(obj["usageFlatFee"]) if obj.get("usageFlatFee") is not None else None,
            "usageOverage": UsageOveragePricingOverride.from_dict(obj["usageOverage"]) if obj.get("usageOverage") is not None else None,
            "usagePerUnit": UsagePerUnitPricingOverride.from_dict(obj["usagePerUnit"]) if obj.get("usagePerUnit") is not None else None,
            "usageTiered": UsageTieredPricingOverride.from_dict(obj["usageTiered"]) if obj.get("usageTiered") is not None else None,
            "usageTieredWithOverage": UsageTieredWithOveragePricingOverride.from_dict(obj["usageTieredWithOverage"]) if obj.get("usageTieredWithOverage") is not None else None,
            "usageVolume": UsageVolumePricingOverride.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:])
