from __future__ import annotations
import datetime
from collections.abc import Callable
from dataclasses import dataclass, field
from kiota_abstractions.serialization import Parsable, ParseNode, SerializationWriter
from typing import Any, Optional, TYPE_CHECKING, Union

@dataclass
class ItemsPatchRequestBody(Parsable):
    # The total price of the main contract item.
    amount: Optional[float] = None
    # A code for the main contract item.Max length: 255
    code: Optional[str] = None
    # A description of the main contract item.Max length: 2048
    description: Optional[str] = None
    # The identifier assigned to an item in its original external ERP system. Use this ID to track and look up data within the integrated system. Note that this value comes from the item's ID in the external system.Max length: 255
    external_id: Optional[str] = None
    # A message generated by the external ERP system that explains the sync status of the integration. For example, common values include ``success`` or ``fail`` to indicate the result of the integration operation.Max length: 255
    external_message: Optional[str] = None
    # The name of the external ERP system integrated with Cost Management. Use this name to identify and search for data within the integrated system.Max length: 255
    external_system: Optional[str] = None
    # The state of the item during the integration with the external ERP system (such as SignNow). An item can be a ``budget``, ``contract``, ``main contract``, ``main contract item``, ``cost item``, ``expense``, ``expense item``, ``change order``, or ``schedule of value``. For more details, see `Integrate with External System </en/docs/acc/v1/tutorials/cost/integrate-with-external-system/>`_ tutorial.Possible values:``locked``: the item is currently locked within the ERP system, preventing modifications until unlocked. To unlock and modify the item, use the relevant PATCH endpoint to set ``integrationState`` to ``null``. For example, for a budget, call `PATCH budgets <en/docs/bim360/v1/reference/http/cost-budgets-budgetId-PATCH/>`_. For a contract, call `PATCH contracts <en/docs/bim360/v1/reference/http/cost-contracts-contractId-PATCH/>`_. For more details, see the `Help documentation <https://help.autodesk.com/view/BUILD/ENU/?guid=Integrated_and_Locked>`_.``integrated``: the item has been successfully added to the ERP system.``failed``: the item encountered an error during the integration process and was not successfully added to the ERP system. For example, if a user tries to integrate ``contracts`` from an ERP system and the updates fail, the ``integrationState`` can be set to ``failed``. Retry the sync process or analyze the issue if it continues to fail.``null``: The item has not been integrated with the ERP system. This is default value.For more information regarding integrations within the Cost Management system, see `Integrations in Cost Management <https://help.autodesk.com/view/BUILD/ENU/?guid=Cost_Integrations>`_.
    integration_state: Optional[str] = None
    # The date and time when the item was last synchronized with the external ERP system. This value is updated by the external system and is in ISO 8601 format.
    last_sync_time: Optional[datetime.datetime] = None
    # The name of the main contract item field to lock so the API can use it to calculate the value of a related field. For example, you can lock the ``unitPrice`` field in the existing main contract item, and the API will use the new value of ``quantity`` that you provide to calculate the new value of ``amount``.Possible values: ``amount``, ``quantity``, and ``unitPrice``.
    locked_field: Optional[str] = None
    # A name for the main contract item.Max length: 1024
    name: Optional[str] = None
    # The position of the main contract item in its siblings of main contract items.
    position: Optional[int] = None
    # The quantity of the main contract item.
    quantity: Optional[float] = None
    # The unit of measure of the main contract item.Max length: 255
    unit: Optional[str] = None
    # The unit price of the main contract item.
    unit_price: Optional[float] = None
    
    @staticmethod
    def create_from_discriminator_value(parse_node: ParseNode) -> ItemsPatchRequestBody:
        """
        Creates a new instance of the appropriate class based on discriminator value
        param parse_node: The parse node to use to read the discriminator value and create the object
        Returns: ItemsPatchRequestBody
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return ItemsPatchRequestBody()
    
    def get_field_deserializers(self,) -> dict[str, Callable[[ParseNode], None]]:
        """
        The deserialization information for the current model
        Returns: dict[str, Callable[[ParseNode], None]]
        """
        fields: dict[str, Callable[[Any], None]] = {
            "amount": lambda n : setattr(self, 'amount', n.get_float_value()),
            "code": lambda n : setattr(self, 'code', n.get_str_value()),
            "description": lambda n : setattr(self, 'description', n.get_str_value()),
            "externalId": lambda n : setattr(self, 'external_id', n.get_str_value()),
            "externalMessage": lambda n : setattr(self, 'external_message', n.get_str_value()),
            "externalSystem": lambda n : setattr(self, 'external_system', n.get_str_value()),
            "integrationState": lambda n : setattr(self, 'integration_state', n.get_str_value()),
            "lastSyncTime": lambda n : setattr(self, 'last_sync_time', n.get_datetime_value()),
            "lockedField": lambda n : setattr(self, 'locked_field', n.get_str_value()),
            "name": lambda n : setattr(self, 'name', n.get_str_value()),
            "position": lambda n : setattr(self, 'position', n.get_int_value()),
            "quantity": lambda n : setattr(self, 'quantity', n.get_float_value()),
            "unit": lambda n : setattr(self, 'unit', n.get_str_value()),
            "unitPrice": lambda n : setattr(self, 'unit_price', n.get_float_value()),
        }
        return fields
    
    def serialize(self,writer: SerializationWriter) -> None:
        """
        Serializes information the current object
        param writer: Serialization writer to use to serialize this model
        Returns: None
        """
        if writer is None:
            raise TypeError("writer cannot be null.")
        writer.write_float_value("amount", self.amount)
        writer.write_str_value("code", self.code)
        writer.write_str_value("description", self.description)
        writer.write_str_value("externalId", self.external_id)
        writer.write_str_value("externalMessage", self.external_message)
        writer.write_str_value("externalSystem", self.external_system)
        writer.write_str_value("integrationState", self.integration_state)
        writer.write_datetime_value("lastSyncTime", self.last_sync_time)
        writer.write_str_value("lockedField", self.locked_field)
        writer.write_str_value("name", self.name)
        writer.write_int_value("position", self.position)
        writer.write_float_value("quantity", self.quantity)
        writer.write_str_value("unit", self.unit)
        writer.write_float_value("unitPrice", self.unit_price)
    

