from __future__ import annotations
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 WithSubCostItemsPatchRequestBody(Parsable):
    # A user-defined identifier for the sub cost item, used for categorization or identification.Max length: 255
    code: Optional[str] = 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 field that is locked for cost calculations. This ensures the locked value remains unchanged during updates. Possible values: ``value``, ``quantity``, ``unitPrice``. For example, if you set ``unitPrice`` at $100, you can adjust the ``quantity`` while keeping the cost fixed.
    locked_field: Optional[str] = None
    # The name to give to the sub cost item.Max length: 1024
    name: Optional[str] = None
    # The planned number of units for the sub cost item.
    quantity: Optional[float] = 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 unit of the sub cost item.
    unit_price: Optional[float] = 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) -> WithSubCostItemsPatchRequestBody:
        """
        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: WithSubCostItemsPatchRequestBody
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return WithSubCostItemsPatchRequestBody()
    
    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]] = {
            "code": lambda n : setattr(self, 'code', n.get_str_value()),
            "inputQuantity": lambda n : setattr(self, 'input_quantity', n.get_float_value()),
            "lockedField": lambda n : setattr(self, 'locked_field', n.get_str_value()),
            "name": lambda n : setattr(self, 'name', n.get_str_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()),
            "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_float_value("inputQuantity", self.input_quantity)
        writer.write_str_value("lockedField", self.locked_field)
        writer.write_str_value("name", self.name)
        writer.write_float_value("quantity", self.quantity)
        writer.write_str_value("unit", self.unit)
        writer.write_float_value("unitPrice", self.unit_price)
        writer.write_float_value("value", self.value)
    

