# coding: utf-8

"""
    CustomerBillingService

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union, Set
from openapi_client.models.billing.insertion_order_pending_changes import InsertionOrderPendingChanges
from openapi_client.models.billing.insertion_order_status import InsertionOrderStatus
from typing_extensions import Self

class InsertionOrder(BaseModel):
    """
    InsertionOrder
    """ # noqa: E501
    account_id: Optional[StrictStr] = Field(default=None, alias="AccountId")
    booking_country_code: Optional[StrictStr] = Field(default=None, alias="BookingCountryCode")
    comment: Optional[StrictStr] = Field(default=None, alias="Comment")
    end_date: Optional[datetime] = Field(default=None, alias="EndDate")
    id: Optional[StrictStr] = Field(default=None, alias="Id")
    last_modified_by_user_id: Optional[StrictStr] = Field(default=None, alias="LastModifiedByUserId")
    last_modified_time: Optional[datetime] = Field(default=None, alias="LastModifiedTime")
    notification_threshold: Optional[StrictFloat] = Field(default=None, alias="NotificationThreshold")
    reference_id: Optional[StrictStr] = Field(default=None, alias="ReferenceId")
    spend_cap_amount: Optional[StrictFloat] = Field(default=None, alias="SpendCapAmount")
    start_date: Optional[datetime] = Field(default=None, alias="StartDate")
    name: Optional[StrictStr] = Field(default=None, alias="Name")
    status: Optional[InsertionOrderStatus] = Field(default=None, alias="Status")
    purchase_order: Optional[StrictStr] = Field(default=None, alias="PurchaseOrder")
    pending_changes: Optional[InsertionOrderPendingChanges] = Field(default=None, alias="PendingChanges")
    account_number: Optional[StrictStr] = Field(default=None, alias="AccountNumber")
    budget_remaining: Optional[StrictFloat] = Field(default=None, alias="BudgetRemaining")
    budget_spent: Optional[StrictFloat] = Field(default=None, alias="BudgetSpent")
    budget_remaining_percent: Optional[StrictFloat] = Field(default=None, alias="BudgetRemainingPercent")
    budget_spent_percent: Optional[StrictFloat] = Field(default=None, alias="BudgetSpentPercent")
    series_name: Optional[StrictStr] = Field(default=None, alias="SeriesName")
    is_in_series: Optional[StrictBool] = Field(default=None, alias="IsInSeries")
    series_frequency_type: Optional[StrictStr] = Field(default=None, alias="SeriesFrequencyType")
    is_unlimited: Optional[StrictBool] = Field(default=None, alias="IsUnlimited")
    is_endless: Optional[StrictBool] = Field(default=None, alias="IsEndless")
    __properties: ClassVar[List[str]] = ["AccountId", "BookingCountryCode", "Comment", "EndDate", "Id", "LastModifiedByUserId", "LastModifiedTime", "NotificationThreshold", "ReferenceId", "SpendCapAmount", "StartDate", "Name", "Status", "PurchaseOrder", "PendingChanges", "AccountNumber", "BudgetRemaining", "BudgetSpent", "BudgetRemainingPercent", "BudgetSpentPercent", "SeriesName", "IsInSeries", "SeriesFrequencyType", "IsUnlimited", "IsEndless"]

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

    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.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of pending_changes
        if self.pending_changes:
            _dict['PendingChanges'] = self.pending_changes.to_dict()
        # set to None if account_id (nullable) is None
        # and model_fields_set contains the field
        if self.account_id is None and "account_id" in self.model_fields_set:
            _dict['AccountId'] = None

        # set to None if booking_country_code (nullable) is None
        # and model_fields_set contains the field
        if self.booking_country_code is None and "booking_country_code" in self.model_fields_set:
            _dict['BookingCountryCode'] = None

        # set to None if comment (nullable) is None
        # and model_fields_set contains the field
        if self.comment is None and "comment" in self.model_fields_set:
            _dict['Comment'] = None

        # set to None if end_date (nullable) is None
        # and model_fields_set contains the field
        if self.end_date is None and "end_date" in self.model_fields_set:
            _dict['EndDate'] = None

        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['Id'] = None

        # set to None if last_modified_by_user_id (nullable) is None
        # and model_fields_set contains the field
        if self.last_modified_by_user_id is None and "last_modified_by_user_id" in self.model_fields_set:
            _dict['LastModifiedByUserId'] = None

        # set to None if last_modified_time (nullable) is None
        # and model_fields_set contains the field
        if self.last_modified_time is None and "last_modified_time" in self.model_fields_set:
            _dict['LastModifiedTime'] = None

        # set to None if notification_threshold (nullable) is None
        # and model_fields_set contains the field
        if self.notification_threshold is None and "notification_threshold" in self.model_fields_set:
            _dict['NotificationThreshold'] = None

        # set to None if reference_id (nullable) is None
        # and model_fields_set contains the field
        if self.reference_id is None and "reference_id" in self.model_fields_set:
            _dict['ReferenceId'] = None

        # set to None if spend_cap_amount (nullable) is None
        # and model_fields_set contains the field
        if self.spend_cap_amount is None and "spend_cap_amount" in self.model_fields_set:
            _dict['SpendCapAmount'] = None

        # set to None if start_date (nullable) is None
        # and model_fields_set contains the field
        if self.start_date is None and "start_date" in self.model_fields_set:
            _dict['StartDate'] = None

        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['Name'] = None

        # set to None if status (nullable) is None
        # and model_fields_set contains the field
        if self.status is None and "status" in self.model_fields_set:
            _dict['Status'] = None

        # set to None if purchase_order (nullable) is None
        # and model_fields_set contains the field
        if self.purchase_order is None and "purchase_order" in self.model_fields_set:
            _dict['PurchaseOrder'] = None

        # set to None if pending_changes (nullable) is None
        # and model_fields_set contains the field
        if self.pending_changes is None and "pending_changes" in self.model_fields_set:
            _dict['PendingChanges'] = None

        # set to None if account_number (nullable) is None
        # and model_fields_set contains the field
        if self.account_number is None and "account_number" in self.model_fields_set:
            _dict['AccountNumber'] = None

        # set to None if budget_remaining (nullable) is None
        # and model_fields_set contains the field
        if self.budget_remaining is None and "budget_remaining" in self.model_fields_set:
            _dict['BudgetRemaining'] = None

        # set to None if budget_spent (nullable) is None
        # and model_fields_set contains the field
        if self.budget_spent is None and "budget_spent" in self.model_fields_set:
            _dict['BudgetSpent'] = None

        # set to None if budget_remaining_percent (nullable) is None
        # and model_fields_set contains the field
        if self.budget_remaining_percent is None and "budget_remaining_percent" in self.model_fields_set:
            _dict['BudgetRemainingPercent'] = None

        # set to None if budget_spent_percent (nullable) is None
        # and model_fields_set contains the field
        if self.budget_spent_percent is None and "budget_spent_percent" in self.model_fields_set:
            _dict['BudgetSpentPercent'] = None

        # set to None if series_name (nullable) is None
        # and model_fields_set contains the field
        if self.series_name is None and "series_name" in self.model_fields_set:
            _dict['SeriesName'] = None

        # set to None if is_in_series (nullable) is None
        # and model_fields_set contains the field
        if self.is_in_series is None and "is_in_series" in self.model_fields_set:
            _dict['IsInSeries'] = None

        # set to None if series_frequency_type (nullable) is None
        # and model_fields_set contains the field
        if self.series_frequency_type is None and "series_frequency_type" in self.model_fields_set:
            _dict['SeriesFrequencyType'] = None

        # set to None if is_unlimited (nullable) is None
        # and model_fields_set contains the field
        if self.is_unlimited is None and "is_unlimited" in self.model_fields_set:
            _dict['IsUnlimited'] = None

        # set to None if is_endless (nullable) is None
        # and model_fields_set contains the field
        if self.is_endless is None and "is_endless" in self.model_fields_set:
            _dict['IsEndless'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "AccountId": obj.get("AccountId") if obj.get("AccountId") is not None else None,
                        "BookingCountryCode": obj.get("BookingCountryCode") if obj.get("BookingCountryCode") is not None else None,
                        "Comment": obj.get("Comment") if obj.get("Comment") is not None else None,
                        "EndDate": obj.get("EndDate") if obj.get("EndDate") is not None else None,
                        "Id": obj.get("Id") if obj.get("Id") is not None else None,
                        "LastModifiedByUserId": obj.get("LastModifiedByUserId") if obj.get("LastModifiedByUserId") is not None else None,
                        "LastModifiedTime": obj.get("LastModifiedTime") if obj.get("LastModifiedTime") is not None else None,
                        "NotificationThreshold": obj.get("NotificationThreshold") if obj.get("NotificationThreshold") is not None else None,
                        "ReferenceId": obj.get("ReferenceId") if obj.get("ReferenceId") is not None else None,
                        "SpendCapAmount": obj.get("SpendCapAmount") if obj.get("SpendCapAmount") is not None else None,
                        "StartDate": obj.get("StartDate") if obj.get("StartDate") is not None else None,
                        "Name": obj.get("Name") if obj.get("Name") is not None else None,
                        "Status": obj.get("Status") if obj.get("Status") is not None else None,
                        "PurchaseOrder": obj.get("PurchaseOrder") if obj.get("PurchaseOrder") is not None else None,
                        "PendingChanges": InsertionOrderPendingChanges.from_dict(obj["PendingChanges"]) if obj.get("PendingChanges") is not None else None,
                        "AccountNumber": obj.get("AccountNumber") if obj.get("AccountNumber") is not None else None,
                        "BudgetRemaining": obj.get("BudgetRemaining") if obj.get("BudgetRemaining") is not None else None,
                        "BudgetSpent": obj.get("BudgetSpent") if obj.get("BudgetSpent") is not None else None,
                        "BudgetRemainingPercent": obj.get("BudgetRemainingPercent") if obj.get("BudgetRemainingPercent") is not None else None,
                        "BudgetSpentPercent": obj.get("BudgetSpentPercent") if obj.get("BudgetSpentPercent") is not None else None,
                        "SeriesName": obj.get("SeriesName") if obj.get("SeriesName") is not None else None,
                        "IsInSeries": obj.get("IsInSeries") if obj.get("IsInSeries") is not None else None,
                        "SeriesFrequencyType": obj.get("SeriesFrequencyType") if obj.get("SeriesFrequencyType") is not None else None,
                        "IsUnlimited": obj.get("IsUnlimited") if obj.get("IsUnlimited") is not None else None,
                        "IsEndless": obj.get("IsEndless") if obj.get("IsEndless") is not None else None
        })
        return _obj
