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

if TYPE_CHECKING:
    from .budgets_get_response_results_budget_code import BudgetsGetResponse_results_budgetCode
    from .budgets_get_response_results_code_segment_values import BudgetsGetResponse_results_codeSegmentValues
    from .budgets_get_response_results_scope import BudgetsGetResponse_results_scope

@dataclass
class BudgetsGetResponse_results(Parsable):
    # The total amount of actual cost of the budget.
    actual_cost: Optional[float] = None
    # Not relevant
    actual_end_date: Optional[str] = None
    # The total of the actual quantity of labor, material,... for the budget.
    actual_quantity: Optional[float] = None
    # Not relevant
    actual_start_date: Optional[str] = None
    # Average unit price for the actual cost of the budget.
    actual_unit_price: Optional[float] = None
    # The total amount of changes committed to the supplier.
    approved_change_orders: Optional[float] = None
    # The total amount of in-scope changes committed to the supplier.
    approved_in_scope_change_orders: Optional[float] = None
    # The total amount of changes approved by the owner
    approved_owner_changes: Optional[float] = None
    # Budget code template and budget segment codes used in the budget. Not applicable for sub-budget.
    budget_code: Optional[BudgetsGetResponse_results_budgetCode] = None
    # Unique code compliant with the budget code template defined by the project admin.Max length: 255
    code: Optional[str] = None
    # Not relevant
    code_segment_values: Optional[BudgetsGetResponse_results_codeSegmentValues] = None
    # Not relevant
    contract_ids: Optional[list[str]] = None
    # Not relevant
    cost_unit_price: Optional[float] = None
    # The date and time that the item was created, in ISO 8601 format.
    created_at: Optional[datetime.datetime] = None
    # The detail description of the budget.Max length: 2048
    description: Optional[str] = None
    # Not relevant
    duration_days: 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 total amount of the forecast cost to complete, equals to ``forecastFinalCost`` - ``actualCost``.
    forecast_cost_complete: Optional[float] = None
    # The total amount of the project cost including forecast adjustments, equals to ``projectedCost`` + ``adjustmentsTotal``.
    forecast_final_cost: Optional[float] = None
    # The total amount of the forecast variance, equals to ``projectedBudget`` - ``forecastFinalCost``.
    forecast_variance: Optional[float] = None
    # Unique identifier of the budget.
    id: Optional[UUID] = None
    # The input quantity planned for the budget.
    input_quantity: Optional[float] = 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
    # Amount of internal transfers between budgets
    internal_adjustment: Optional[float] = None
    # Not relevant
    is_markup: Optional[bool] = 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
    # A list of the IDs of the project locations where this item applies, along with the node paths of these locations in the project's locations tree.For more information, see the Locations `Help documentation <https://aps.autodesk.com/en/docs/bim360/v1/reference/http/locations-nodes-GET/>`_ help.
    location_paths: Optional[list[str]] = None
    # A list of the IDs of the project locations where this item applies.For more information, see the Locations `Help documentation <https://aps.autodesk.com/en/docs/bim360/v1/reference/http/locations-nodes-GET/>`_ help.
    locations: Optional[list[str]] = None
    # Not relevant
    main_contract_amount_source: Optional[str] = None
    # Not relevant
    main_contract_id: Optional[UUID] = None
    # Not relevant
    milestone_id: Optional[str] = None
    # The name of the budget.Max length: 1024
    name: Optional[str] = None
    # Original amount of the budget, equals to ``quantity`` * ``unitPrice``
    original_amount: Optional[float] = None
    # The original amount committed in the supplier contract.
    original_commitment: Optional[float] = None
    # ID of a parent budget, ``null`` for root budgets.
    parent_id: Optional[str] = None
    # The total amount of changes not committed to the supplier.
    pending_change_orders: Optional[float] = None
    # The total amount of changes waiting for the approval by the owner
    pending_owner_changes: Optional[float] = None
    # Not relevant
    planned_end_date: Optional[str] = None
    # Not relevant
    planned_start_date: Optional[str] = None
    # The total amount of the project budget including pending changes, equals to ``revised`` + ``pendingOwnerChanges``.
    projected_budget: Optional[float] = None
    # The total amount of the project cost. For a budget, it is equal to ``originalCommitment`` + ``approvedChangeOrders`` + ``pendingChangeOrders`` + ``reserves``. For a contract , it is equal to ``awarded`` + ``approvedChangeOrders`` + ``pendingChangeOrders`` + ``reserves``.
    projected_cost: Optional[float] = None
    # The quantity of labor, material,... planned for the budget.
    quantity: Optional[float] = None
    # The ratio of the quantity the resources used on the budget.
    ratio: Optional[float] = None
    # The total amount of changes under estimation.
    reserves: Optional[float] = None
    # The total amount of the approved budget from the owner, equals to ``originalAmount`` + ``internalAdjustment`` + ``approvedOwnerChanges``.
    revised: Optional[float] = None
    # The scope of the budget. Possible values are ``budgetOnly`` and ``budgetAndCost``.
    scope: Optional[BudgetsGetResponse_results_scope] = None
    # The sub-budget in the root budget.Max length: 255
    sub_items: Optional[list[str]] = None
    # The amount that has been approved by owner but not committed to the supplier. This is calculated as ``approvedOwnerChanges`` - (``approvedChangeOrders`` - ``approvedInScopeChangeOrders``).
    uncommitted: Optional[float] = None
    # Unit of measures used in the budget.
    unit: Optional[str] = None
    # Unit price of a budget.
    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
    # The total amount of the variance of a budget, equals to ``projectedBudget`` - ``projectedCost``.
    variance_total: Optional[float] = None
    
    @staticmethod
    def create_from_discriminator_value(parse_node: ParseNode) -> BudgetsGetResponse_results:
        """
        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: BudgetsGetResponse_results
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return BudgetsGetResponse_results()
    
    def get_field_deserializers(self,) -> dict[str, Callable[[ParseNode], None]]:
        """
        The deserialization information for the current model
        Returns: dict[str, Callable[[ParseNode], None]]
        """
        from .budgets_get_response_results_budget_code import BudgetsGetResponse_results_budgetCode
        from .budgets_get_response_results_code_segment_values import BudgetsGetResponse_results_codeSegmentValues
        from .budgets_get_response_results_scope import BudgetsGetResponse_results_scope

        from .budgets_get_response_results_budget_code import BudgetsGetResponse_results_budgetCode
        from .budgets_get_response_results_code_segment_values import BudgetsGetResponse_results_codeSegmentValues
        from .budgets_get_response_results_scope import BudgetsGetResponse_results_scope

        fields: dict[str, Callable[[Any], None]] = {
            "actualCost": lambda n : setattr(self, 'actual_cost', n.get_float_value()),
            "actualEndDate": lambda n : setattr(self, 'actual_end_date', n.get_str_value()),
            "actualQuantity": lambda n : setattr(self, 'actual_quantity', n.get_float_value()),
            "actualStartDate": lambda n : setattr(self, 'actual_start_date', n.get_str_value()),
            "actualUnitPrice": lambda n : setattr(self, 'actual_unit_price', n.get_float_value()),
            "approvedChangeOrders": lambda n : setattr(self, 'approved_change_orders', n.get_float_value()),
            "approvedInScopeChangeOrders": lambda n : setattr(self, 'approved_in_scope_change_orders', n.get_float_value()),
            "approvedOwnerChanges": lambda n : setattr(self, 'approved_owner_changes', n.get_float_value()),
            "budgetCode": lambda n : setattr(self, 'budget_code', n.get_object_value(BudgetsGetResponse_results_budgetCode)),
            "code": lambda n : setattr(self, 'code', n.get_str_value()),
            "codeSegmentValues": lambda n : setattr(self, 'code_segment_values', n.get_object_value(BudgetsGetResponse_results_codeSegmentValues)),
            "contractIds": lambda n : setattr(self, 'contract_ids', n.get_collection_of_primitive_values(str)),
            "costUnitPrice": lambda n : setattr(self, 'cost_unit_price', n.get_float_value()),
            "createdAt": lambda n : setattr(self, 'created_at', n.get_datetime_value()),
            "description": lambda n : setattr(self, 'description', n.get_str_value()),
            "durationDays": lambda n : setattr(self, 'duration_days', 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()),
            "forecastCostComplete": lambda n : setattr(self, 'forecast_cost_complete', n.get_float_value()),
            "forecastFinalCost": lambda n : setattr(self, 'forecast_final_cost', n.get_float_value()),
            "forecastVariance": lambda n : setattr(self, 'forecast_variance', n.get_float_value()),
            "id": lambda n : setattr(self, 'id', n.get_uuid_value()),
            "inputQuantity": lambda n : setattr(self, 'input_quantity', n.get_float_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()),
            "internalAdjustment": lambda n : setattr(self, 'internal_adjustment', n.get_float_value()),
            "isMarkup": lambda n : setattr(self, 'is_markup', n.get_bool_value()),
            "lastSyncTime": lambda n : setattr(self, 'last_sync_time', n.get_datetime_value()),
            "locationPaths": lambda n : setattr(self, 'location_paths', n.get_collection_of_primitive_values(str)),
            "locations": lambda n : setattr(self, 'locations', n.get_collection_of_primitive_values(str)),
            "mainContractAmountSource": lambda n : setattr(self, 'main_contract_amount_source', n.get_str_value()),
            "mainContractId": lambda n : setattr(self, 'main_contract_id', n.get_uuid_value()),
            "milestoneId": lambda n : setattr(self, 'milestone_id', n.get_str_value()),
            "name": lambda n : setattr(self, 'name', n.get_str_value()),
            "originalAmount": lambda n : setattr(self, 'original_amount', n.get_float_value()),
            "originalCommitment": lambda n : setattr(self, 'original_commitment', n.get_float_value()),
            "parentId": lambda n : setattr(self, 'parent_id', n.get_str_value()),
            "pendingChangeOrders": lambda n : setattr(self, 'pending_change_orders', n.get_float_value()),
            "pendingOwnerChanges": lambda n : setattr(self, 'pending_owner_changes', n.get_float_value()),
            "plannedEndDate": lambda n : setattr(self, 'planned_end_date', n.get_str_value()),
            "plannedStartDate": lambda n : setattr(self, 'planned_start_date', n.get_str_value()),
            "projectedBudget": lambda n : setattr(self, 'projected_budget', n.get_float_value()),
            "projectedCost": lambda n : setattr(self, 'projected_cost', n.get_float_value()),
            "quantity": lambda n : setattr(self, 'quantity', n.get_float_value()),
            "ratio": lambda n : setattr(self, 'ratio', n.get_float_value()),
            "reserves": lambda n : setattr(self, 'reserves', n.get_float_value()),
            "revised": lambda n : setattr(self, 'revised', n.get_float_value()),
            "scope": lambda n : setattr(self, 'scope', n.get_enum_value(BudgetsGetResponse_results_scope)),
            "subItems": lambda n : setattr(self, 'sub_items', n.get_collection_of_primitive_values(str)),
            "uncommitted": lambda n : setattr(self, 'uncommitted', 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()),
            "updatedAt": lambda n : setattr(self, 'updated_at', n.get_datetime_value()),
            "varianceTotal": lambda n : setattr(self, 'variance_total', 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("actualCost", self.actual_cost)
        writer.write_str_value("actualEndDate", self.actual_end_date)
        writer.write_float_value("actualQuantity", self.actual_quantity)
        writer.write_str_value("actualStartDate", self.actual_start_date)
        writer.write_float_value("actualUnitPrice", self.actual_unit_price)
        writer.write_float_value("approvedChangeOrders", self.approved_change_orders)
        writer.write_float_value("approvedInScopeChangeOrders", self.approved_in_scope_change_orders)
        writer.write_float_value("approvedOwnerChanges", self.approved_owner_changes)
        writer.write_object_value("budgetCode", self.budget_code)
        writer.write_str_value("code", self.code)
        writer.write_object_value("codeSegmentValues", self.code_segment_values)
        writer.write_collection_of_primitive_values("contractIds", self.contract_ids)
        writer.write_float_value("costUnitPrice", self.cost_unit_price)
        writer.write_datetime_value("createdAt", self.created_at)
        writer.write_str_value("description", self.description)
        writer.write_float_value("durationDays", self.duration_days)
        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_float_value("forecastCostComplete", self.forecast_cost_complete)
        writer.write_float_value("forecastFinalCost", self.forecast_final_cost)
        writer.write_float_value("forecastVariance", self.forecast_variance)
        writer.write_uuid_value("id", self.id)
        writer.write_float_value("inputQuantity", self.input_quantity)
        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_float_value("internalAdjustment", self.internal_adjustment)
        writer.write_bool_value("isMarkup", self.is_markup)
        writer.write_datetime_value("lastSyncTime", self.last_sync_time)
        writer.write_collection_of_primitive_values("locationPaths", self.location_paths)
        writer.write_collection_of_primitive_values("locations", self.locations)
        writer.write_str_value("mainContractAmountSource", self.main_contract_amount_source)
        writer.write_uuid_value("mainContractId", self.main_contract_id)
        writer.write_str_value("milestoneId", self.milestone_id)
        writer.write_str_value("name", self.name)
        writer.write_float_value("originalAmount", self.original_amount)
        writer.write_float_value("originalCommitment", self.original_commitment)
        writer.write_str_value("parentId", self.parent_id)
        writer.write_float_value("pendingChangeOrders", self.pending_change_orders)
        writer.write_float_value("pendingOwnerChanges", self.pending_owner_changes)
        writer.write_str_value("plannedEndDate", self.planned_end_date)
        writer.write_str_value("plannedStartDate", self.planned_start_date)
        writer.write_float_value("projectedBudget", self.projected_budget)
        writer.write_float_value("projectedCost", self.projected_cost)
        writer.write_float_value("quantity", self.quantity)
        writer.write_float_value("ratio", self.ratio)
        writer.write_float_value("reserves", self.reserves)
        writer.write_float_value("revised", self.revised)
        writer.write_enum_value("scope", self.scope)
        writer.write_collection_of_primitive_values("subItems", self.sub_items)
        writer.write_float_value("uncommitted", self.uncommitted)
        writer.write_str_value("unit", self.unit)
        writer.write_float_value("unitPrice", self.unit_price)
        writer.write_datetime_value("updatedAt", self.updated_at)
        writer.write_float_value("varianceTotal", self.variance_total)
    

