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 .with_sub_cost_items_patch_response_type import WithSubCostItemsPatchResponse_type

@dataclass
class WithSubCostItemsPatchResponse(Parsable):
    # The identifier for the sub cost item. If copied from another model, for example, a ``Contract SOV``, it inherits the code. Otherwise, it is manually assigned.Max length: 255
    code: Optional[str] = None
    # The ID of the cost item to which the sub cost item belongs.
    cost_item_id: Optional[str] = None
    # The date and time that the item was created, in ISO 8601 format.
    created_at: Optional[datetime.datetime] = None
    # The unique ID of the sub cost item.
    id: Optional[UUID] = None
    # The recorded input quantity, typically used in performance tracking. For example, in labor tracking, ``inputQuantity`` represents man-hours utilized.
    input_quantity: Optional[float] = None
    # The name of the sub cost item.Max length: 1024
    name: Optional[str] = None
    # The unique ID of the parent sub cost item. A sub cost item has a parent Id when it is part of a hierarchical cost structure. Root sub cost items do not have a parent ID.
    parent_id: Optional[str] = None
    # The position of the sub cost item relative to its sibling sub cost items. If a new sub cost item is assigned a position that already exists, the system shifts existing items downward to maintain order.
    position: Optional[float] = None
    # The planned number of units allocated for the sub cost item.
    quantity: Optional[float] = None
    # The classification of the sub cost item that indicates its role in cost tracking and approval workflows. Possible values: ``estimated``, ``proposed``, ``submitted``, ``approved``, ``committed``.Max length: 255
    type: Optional[WithSubCostItemsPatchResponse_type] = None
    # The unit of measurement for the sub cost item. This value is configured in the ``Unit of measure`` settings for the project. Common units include ``ea`` (Each), ``gal`` (Gallon), and various volume, length, and time measurements.Max length: 1024
    unit: Optional[str] = None
    # The price per individual unit of the sub cost 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
    # The total value of the sub cost item, calculated as ``quantity`` * ``unitPrice``.
    value: Optional[float] = None
    
    @staticmethod
    def create_from_discriminator_value(parse_node: ParseNode) -> WithSubCostItemsPatchResponse:
        """
        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: WithSubCostItemsPatchResponse
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return WithSubCostItemsPatchResponse()
    
    def get_field_deserializers(self,) -> dict[str, Callable[[ParseNode], None]]:
        """
        The deserialization information for the current model
        Returns: dict[str, Callable[[ParseNode], None]]
        """
        from .with_sub_cost_items_patch_response_type import WithSubCostItemsPatchResponse_type

        from .with_sub_cost_items_patch_response_type import WithSubCostItemsPatchResponse_type

        fields: dict[str, Callable[[Any], None]] = {
            "code": lambda n : setattr(self, 'code', n.get_str_value()),
            "costItemId": lambda n : setattr(self, 'cost_item_id', n.get_str_value()),
            "createdAt": lambda n : setattr(self, 'created_at', n.get_datetime_value()),
            "id": lambda n : setattr(self, 'id', n.get_uuid_value()),
            "inputQuantity": lambda n : setattr(self, 'input_quantity', n.get_float_value()),
            "name": lambda n : setattr(self, 'name', n.get_str_value()),
            "parentId": lambda n : setattr(self, 'parent_id', n.get_str_value()),
            "position": lambda n : setattr(self, 'position', n.get_float_value()),
            "quantity": lambda n : setattr(self, 'quantity', n.get_float_value()),
            "type": lambda n : setattr(self, 'type', n.get_enum_value(WithSubCostItemsPatchResponse_type)),
            "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()),
            "value": lambda n : setattr(self, 'value', 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_str_value("code", self.code)
        writer.write_str_value("costItemId", self.cost_item_id)
        writer.write_datetime_value("createdAt", self.created_at)
        writer.write_uuid_value("id", self.id)
        writer.write_float_value("inputQuantity", self.input_quantity)
        writer.write_str_value("name", self.name)
        writer.write_str_value("parentId", self.parent_id)
        writer.write_float_value("position", self.position)
        writer.write_float_value("quantity", self.quantity)
        writer.write_enum_value("type", self.type)
        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("value", self.value)
    

