# 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 datetime import date
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from zuora_sdk.models.order_line_item_billing_rule import OrderLineItemBillingRule
from zuora_sdk.models.order_line_item_inline_discount_type import OrderLineItemInlineDiscountType
from zuora_sdk.models.order_line_item_state import OrderLineItemState
from zuora_sdk.models.order_line_item_type import OrderLineItemType
from zuora_sdk.models.tax_mode import TaxMode
from typing import Optional, Set
from typing_extensions import Self

class BulkUpdateOrderLineItem(BaseModel):
    """
    BulkUpdateOrderLineItem
    """ # 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)

    uom: Optional[StrictStr] = Field(default=None, description="Specifies the units to measure usage.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="UOM")
    accounting_code: Optional[StrictStr] = Field(default=None, description="The accountingCode for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="accountingCode")
    adjustment_liability_accounting_code: Optional[StrictStr] = Field(default=None, description="The accounting code on the Order Line Item object for customers using [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="adjustmentLiabilityAccountingCode")
    adjustment_revenue_accounting_code: Optional[StrictStr] = Field(default=None, description="The accounting code on the Order Line Item object for customers using [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="adjustmentRevenueAccountingCode")
    amount_per_unit: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The actual charged amount per unit for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="amountPerUnit")
    bill_target_date: Optional[date] = Field(default=None, description="The target date for the Order Line Item (OLI) to be picked up by bill run for generating billing documents.  To generate billing documents for an OLI, you must set this field and set the `itemState` field to `SentToBilling`.  You can update this field for a sales or return OLI only when the OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="billTargetDate")
    bill_to: Optional[StrictStr] = Field(default=None, description="The ID of a contact that belongs to the billing account of the order line item. Use this field to assign an existing account as the bill-to contact of an order line item.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="billTo")
    billing_rule: Optional[OrderLineItemBillingRule] = Field(default=OrderLineItemBillingRule.TRIGGERWITHOUTFULFILLMENT, alias="billingRule")
    contract_asset_accounting_code: Optional[StrictStr] = Field(default=None, description="The accounting code on the Order Line Item object for customers using [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="contractAssetAccountingCode")
    contract_liability_accounting_code: Optional[StrictStr] = Field(default=None, description="The accounting code on the Order Line Item object for customers using [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="contractLiabilityAccountingCode")
    contract_recognized_revenue_accounting_code: Optional[StrictStr] = Field(default=None, description="The accounting code on the Order Line Item object for customers using [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="contractRecognizedRevenueAccountingCode")
    custom_fields: Optional[Dict[str, Any]] = Field(default=None, description="Container for custom fields of an Order Line Item object. ", alias="customFields")
    deferred_revenue_accounting_code: Optional[StrictStr] = Field(default=None, description="The deferred revenue accounting code for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="deferredRevenueAccountingCode")
    description: Optional[StrictStr] = Field(default=None, description="The description of the Order Line Item (OLI).  You can update this field for a sales or return OLI only when the OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ")
    inline_discount_per_unit: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`).  Use this field in accordance with the `inlineDiscountType` field, in the following manner: * If the `inlineDiscountType` field is set as `Percentage`, this field specifies the discount percentage for each unit of the order line item. For exmaple, if you specify `5` in this field, the discount percentage is 5%. * If the `inlineDiscountType` field is set as `FixedAmount`, this field specifies the discount amount on each unit of the order line item. For exmaple, if you specify `10` in this field, the discount amount on each unit of the order line item is 10.  Once you set the `inlineDiscountType`, `inlineDiscountPerUnit`, and `listPricePerUnit` fields, the system will automatically generate the `amountPerUnit` field. You shall not set the `amountPerUnit` field by yourself. ", alias="inlineDiscountPerUnit")
    inline_discount_type: Optional[OrderLineItemInlineDiscountType] = Field(default=None, alias="inlineDiscountType")
    invoice_group_number: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="The invoice group number associated with the order line item.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing`/`Booked`/`SentToBilling` state (when the `itemState` field is set as `Executing`/`Booked`/`SentToBilling`). ", alias="invoiceGroupNumber")
    is_allocation_eligible: Optional[StrictBool] = Field(default=None, description="This field is used to identify if the charge segment is allocation eligible in revenue recognition.  **Note**: This feature is in the **Early Adopter** phase. If you want to use the feature, submit a request at <a href=\"https://support.zuora.com/\" target=\"_blank\">Zuora Global Support</a>, and we will evaluate whether the feature is suitable for your use cases. ", alias="isAllocationEligible")
    is_unbilled: Optional[StrictBool] = Field(default=None, description="This field is used to dictate how to perform the accounting during revenue recognition.  **Note**: This feature is in the **Early Adopter** phase. If you want to use the feature, submit a request at <a href=\"https://support.zuora.com/\" target=\"_blank\">Zuora Global Support</a>, and we will evaluate whether the feature is suitable for your use cases. ", alias="isUnbilled")
    exclude_item_billing_from_revenue_accounting: Optional[StrictBool] = Field(default=None, description="The flag to exclude Order Line Item related invoice items, invoice item adjustments, credit memo items, and debit memo items from revenue accounting.   **Note**: This field is only available if you have the Billing - Revenue Integration feature enabled.  ", alias="excludeItemBillingFromRevenueAccounting")
    exclude_item_booking_from_revenue_accounting: Optional[StrictBool] = Field(default=None, description="The flag to exclude Order Line Item from revenue accounting.  **Note**: This field is only available if you have the Billing - Revenue Integration feature enabled. ", alias="excludeItemBookingFromRevenueAccounting")
    revenue_recognition_timing: Optional[StrictStr] = Field(default=None, description="This field is used to dictate the type of revenue recognition timing.", alias="revenueRecognitionTiming")
    revenue_amortization_method: Optional[StrictStr] = Field(default=None, description="This field is used to dictate the type of revenue amortization method.", alias="revenueAmortizationMethod")
    item_name: Optional[StrictStr] = Field(default=None, description="The name of the Order Line Item (OLI).  You can update this field for a sales or return OLI only when the OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="itemName")
    item_number: Optional[StrictStr] = Field(default=None, description="The number for the Order Line Item (OLI).  You can update this field for a sales or return OLI only when the OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="itemNumber")
    item_state: Optional[OrderLineItemState] = Field(default=None, alias="itemState")
    item_type: Optional[OrderLineItemType] = Field(default=None, alias="itemType")
    list_price_per_unit: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The list price per unit for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="listPricePerUnit")
    owner_account_number: Optional[StrictStr] = Field(default=None, description="Use this field to assign an existing account as the owner of an order line item.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="ownerAccountNumber")
    product_code: Optional[StrictStr] = Field(default=None, description="The product code for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="productCode")
    purchase_order_number: Optional[StrictStr] = Field(default=None, description="Used by customers to specify the Purchase Order Number provided by the buyer.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="purchaseOrderNumber")
    quantity: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The quantity of units, such as the number of authors in a hosted wiki service.  You can update this field for a sales or return OLI only when the OLI in the `Executing` state (when the `itemState` field is set as `Executing`). ")
    recognized_revenue_accounting_code: Optional[StrictStr] = Field(default=None, description="The recognized revenue accounting code for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="recognizedRevenueAccountingCode")
    related_subscription_number: Optional[StrictStr] = Field(default=None, description="Use this field to relate an order line item to an subscription. Specify this field to the subscription number of the subscription to relate.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="relatedSubscriptionNumber")
    revenue_recognition_rule: Optional[StrictStr] = Field(default=None, description="The Revenue Recognition rule for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="revenueRecognitionRule")
    sequence_set_id: Optional[StrictStr] = Field(default=None, description="The ID of the sequence set associated with the orderLineItem. You can update this field only for a sales OLI and only when the sales OLI is in the `Executing`/`Booked`/`SentToBilling` state (when the `itemState` field is set as `Executing`/`Booked`/`SentToBilling`). ", alias="sequenceSetId")
    payment_term: Optional[StrictStr] = Field(default=None, description="The payment term name associated with the orderLineItem. You can update this field only for a sales OLI and only when the sales OLI is in the `Executing`/`Booked`/`SentToBilling` state (when the `itemState` field is set as `Executing`/`Booked`/`SentToBilling`). ", alias="paymentTerm")
    invoice_template_id: Optional[StrictStr] = Field(default=None, description="The ID of the invoice template associated with the orderLineItem. You can update this field only for a sales OLI and only when the sales OLI is in the `Executing`/`Booked`/`SentToBilling` state (when the `itemState` field is set as `Executing`/`Booked`/`SentToBilling`). ", alias="invoiceTemplateId")
    sold_to: Optional[StrictStr] = Field(default=None, description="Use this field to assign an existing account as the sold-to contact of an order line item, by the following rules:  * If the `ownerAccountNumber` field is set, then this field must be the ID of a contact that belongs to the owner account of the order line item.  * If the `ownerAccountNumber` field is not set, then this field must be the ID of a contact that belongs to the billing account of the order line item.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="soldTo")
    ship_to: Optional[StrictStr] = Field(default=None, description="Use this field to assign an existing account as the ship-to contact of an order line item, by the following rules:  * If the `ownerAccountNumber` field is set, then this field must be the ID of a contact that belongs to the owner account of the order line item.  * If the `ownerAccountNumber` field is not set, then this field must be the ID of a contact that belongs to the billing account of the order line item.  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="shipTo")
    tax_code: Optional[StrictStr] = Field(default=None, description="The tax code for the Order Line Item (OLI).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="taxCode")
    tax_mode: Optional[TaxMode] = Field(default=None, alias="taxMode")
    transaction_end_date: Optional[date] = Field(default=None, description="The date a transaction is completed. The default value of this field is the transaction start date. Also, the value of this field should always equal or be later than the value of the `transactionStartDate` field.  You can update this field for a sales or return OLI only when the OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="transactionEndDate")
    transaction_start_date: Optional[date] = Field(default=None, description="The date a transaction starts. The default value of this field is the order date.  You can update this field for a sales or return OLI only when the OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="transactionStartDate")
    unbilled_receivables_accounting_code: Optional[StrictStr] = Field(default=None, description="The accounting code on the Order Line Item object for customers using [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration).  You can update this field only for a sales OLI and only when the sales OLI is in the `Executing` state (when the `itemState` field is set as `Executing`). ", alias="unbilledReceivablesAccountingCode")
    id: StrictStr = Field(description="The sytem generated Id for the Order Line Item(OLI). Use this field to specify which OLI to update. ")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["UOM", "accountingCode", "adjustmentLiabilityAccountingCode", "adjustmentRevenueAccountingCode", "amountPerUnit", "billTargetDate", "billTo", "billingRule", "contractAssetAccountingCode", "contractLiabilityAccountingCode", "contractRecognizedRevenueAccountingCode", "customFields", "deferredRevenueAccountingCode", "description", "inlineDiscountPerUnit", "inlineDiscountType", "invoiceGroupNumber", "isAllocationEligible", "isUnbilled", "excludeItemBillingFromRevenueAccounting", "excludeItemBookingFromRevenueAccounting", "revenueRecognitionTiming", "revenueAmortizationMethod", "itemName", "itemNumber", "itemState", "itemType", "listPricePerUnit", "ownerAccountNumber", "productCode", "purchaseOrderNumber", "quantity", "recognizedRevenueAccountingCode", "relatedSubscriptionNumber", "revenueRecognitionRule", "sequenceSetId", "paymentTerm", "invoiceTemplateId", "soldTo", "shipTo", "taxCode", "taxMode", "transactionEndDate", "transactionStartDate", "unbilledReceivablesAccountingCode", "id"]

    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 BulkUpdateOrderLineItem 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,
        )
        # 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 BulkUpdateOrderLineItem 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 {
            "UOM": obj.get("UOM"),
            "accountingCode": obj.get("accountingCode"),
            "adjustmentLiabilityAccountingCode": obj.get("adjustmentLiabilityAccountingCode"),
            "adjustmentRevenueAccountingCode": obj.get("adjustmentRevenueAccountingCode"),
            "amountPerUnit": obj.get("amountPerUnit"),
            "billTargetDate": obj.get("billTargetDate"),
            "billTo": obj.get("billTo"),
            "billingRule": obj.get("billingRule") if obj.get("billingRule") is not None else OrderLineItemBillingRule.TRIGGERWITHOUTFULFILLMENT,
            "contractAssetAccountingCode": obj.get("contractAssetAccountingCode"),
            "contractLiabilityAccountingCode": obj.get("contractLiabilityAccountingCode"),
            "contractRecognizedRevenueAccountingCode": obj.get("contractRecognizedRevenueAccountingCode"),
            "customFields": obj.get("customFields"),
            "deferredRevenueAccountingCode": obj.get("deferredRevenueAccountingCode"),
            "description": obj.get("description"),
            "inlineDiscountPerUnit": obj.get("inlineDiscountPerUnit"),
            "inlineDiscountType": obj.get("inlineDiscountType"),
            "invoiceGroupNumber": obj.get("invoiceGroupNumber"),
            "isAllocationEligible": obj.get("isAllocationEligible"),
            "isUnbilled": obj.get("isUnbilled"),
            "excludeItemBillingFromRevenueAccounting": obj.get("excludeItemBillingFromRevenueAccounting"),
            "excludeItemBookingFromRevenueAccounting": obj.get("excludeItemBookingFromRevenueAccounting"),
            "revenueRecognitionTiming": obj.get("revenueRecognitionTiming"),
            "revenueAmortizationMethod": obj.get("revenueAmortizationMethod"),
            "itemName": obj.get("itemName"),
            "itemNumber": obj.get("itemNumber"),
            "itemState": obj.get("itemState"),
            "itemType": obj.get("itemType"),
            "listPricePerUnit": obj.get("listPricePerUnit"),
            "ownerAccountNumber": obj.get("ownerAccountNumber"),
            "productCode": obj.get("productCode"),
            "purchaseOrderNumber": obj.get("purchaseOrderNumber"),
            "quantity": obj.get("quantity"),
            "recognizedRevenueAccountingCode": obj.get("recognizedRevenueAccountingCode"),
            "relatedSubscriptionNumber": obj.get("relatedSubscriptionNumber"),
            "revenueRecognitionRule": obj.get("revenueRecognitionRule"),
            "sequenceSetId": obj.get("sequenceSetId"),
            "paymentTerm": obj.get("paymentTerm"),
            "invoiceTemplateId": obj.get("invoiceTemplateId"),
            "soldTo": obj.get("soldTo"),
            "shipTo": obj.get("shipTo"),
            "taxCode": obj.get("taxCode"),
            "taxMode": obj.get("taxMode"),
            "transactionEndDate": obj.get("transactionEndDate"),
            "transactionStartDate": obj.get("transactionStartDate"),
            "unbilledReceivablesAccountingCode": obj.get("unbilledReceivablesAccountingCode"),
            "id": obj.get("id")
        }
        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:])
