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
from uuid import UUID

@dataclass
class ItemsGetResponse(Parsable):
    # The aggregate type of the expense item.Possible values: ``workCompleted``, ``workCompletedQty``, ``materialsOnSite``
    aggregate_by: Optional[str] = None
    # The total price of the expense item.
    amount: Optional[float] = None
    # The ID of the budget to which the expense item belongs.
    budget_id: Optional[str] = None
    # The ID of the contract to which the expense item belongs.
    contract_id: Optional[UUID] = None
    # The date and time that the item was created, in ISO 8601 format.
    created_at: Optional[datetime.datetime] = None
    # The detailed description of the expense item.Max length: 2048
    description: Optional[str] = None
    # The exchange rate that applies to the expense item's base currency price. For example, provide the value ``0.7455`` for a foreign currency that's worth ``0.7455`` of your base currency. Default:``1``. It's also ``1`` if multi-currency is not enabled.
    exchange_rate: Optional[float] = 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 unique identifier of the expense item.
    id: Optional[UUID] = 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 that the item's integration status was last changed.
    integration_state_changed_at: Optional[str] = None
    # The user who last changed the integration status. This is the ID of a user managed by the BIM 360/ACC Admin.
    integration_state_changed_by: 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 expense item.Max length: 1024
    name: Optional[str] = None
    # The note attached to the expense item, if returned. The note consists of Tiptap formatted rich text. For more information, see `https://tiptap.dev <https://tiptap.dev/introduction/>`_.
    note: Optional[str] = None
    # The sequence number for the expense item.
    number: Optional[str] = None
    # The original exchange rate from the expense item's associated contract. Default:``1``. It's also ``1`` if multi-currency is not enabled.
    original_exchange_rate: Optional[float] = None
    # The number of units of the expense item.
    quantity: Optional[float] = None
    # The gain or loss on the expense item, calculated as follows:``amount * exchangeRate / originalExchangeRate - amount``
    realized_gain_or_loss: Optional[float] = None
    # The applicable scope of the expense item. Possible values: ``full``, ``partial``.
    scope: Optional[str] = None
    # The expense item's unit of measure.
    unit: Optional[str] = None
    # The price per unit of the expense item.
    unit_price: Optional[float] = None
    # The date and time that the item was last updated, in ISO 8601 format.
    updated_at: Optional[datetime.datetime] = None
    
    @staticmethod
    def create_from_discriminator_value(parse_node: ParseNode) -> ItemsGetResponse:
        """
        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: ItemsGetResponse
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return ItemsGetResponse()
    
    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]] = {
            "aggregateBy": lambda n : setattr(self, 'aggregate_by', n.get_str_value()),
            "amount": lambda n : setattr(self, 'amount', n.get_float_value()),
            "budgetId": lambda n : setattr(self, 'budget_id', n.get_str_value()),
            "contractId": lambda n : setattr(self, 'contract_id', n.get_uuid_value()),
            "createdAt": lambda n : setattr(self, 'created_at', n.get_datetime_value()),
            "description": lambda n : setattr(self, 'description', n.get_str_value()),
            "exchangeRate": lambda n : setattr(self, 'exchange_rate', n.get_float_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()),
            "id": lambda n : setattr(self, 'id', n.get_uuid_value()),
            "integrationState": lambda n : setattr(self, 'integration_state', n.get_str_value()),
            "integrationStateChangedAt": lambda n : setattr(self, 'integration_state_changed_at', n.get_str_value()),
            "integrationStateChangedBy": lambda n : setattr(self, 'integration_state_changed_by', n.get_str_value()),
            "lastSyncTime": lambda n : setattr(self, 'last_sync_time', n.get_datetime_value()),
            "name": lambda n : setattr(self, 'name', n.get_str_value()),
            "note": lambda n : setattr(self, 'note', n.get_str_value()),
            "number": lambda n : setattr(self, 'number', n.get_str_value()),
            "originalExchangeRate": lambda n : setattr(self, 'original_exchange_rate', n.get_float_value()),
            "quantity": lambda n : setattr(self, 'quantity', n.get_float_value()),
            "realizedGainOrLoss": lambda n : setattr(self, 'realized_gain_or_loss', n.get_float_value()),
            "scope": lambda n : setattr(self, 'scope', n.get_str_value()),
            "unit": lambda n : setattr(self, 'unit', n.get_str_value()),
            "unitPrice": lambda n : setattr(self, 'unit_price', n.get_float_value()),
            "updatedAt": lambda n : setattr(self, 'updated_at', n.get_datetime_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_str_value("aggregateBy", self.aggregate_by)
        writer.write_float_value("amount", self.amount)
        writer.write_str_value("budgetId", self.budget_id)
        writer.write_uuid_value("contractId", self.contract_id)
        writer.write_datetime_value("createdAt", self.created_at)
        writer.write_str_value("description", self.description)
        writer.write_float_value("exchangeRate", self.exchange_rate)
        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_uuid_value("id", self.id)
        writer.write_str_value("integrationState", self.integration_state)
        writer.write_str_value("integrationStateChangedAt", self.integration_state_changed_at)
        writer.write_str_value("integrationStateChangedBy", self.integration_state_changed_by)
        writer.write_datetime_value("lastSyncTime", self.last_sync_time)
        writer.write_str_value("name", self.name)
        writer.write_str_value("note", self.note)
        writer.write_str_value("number", self.number)
        writer.write_float_value("originalExchangeRate", self.original_exchange_rate)
        writer.write_float_value("quantity", self.quantity)
        writer.write_float_value("realizedGainOrLoss", self.realized_gain_or_loss)
        writer.write_str_value("scope", self.scope)
        writer.write_str_value("unit", self.unit)
        writer.write_float_value("unitPrice", self.unit_price)
        writer.write_datetime_value("updatedAt", self.updated_at)
    

