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

if TYPE_CHECKING:
    from .contracts_post_response_additional_contacts import ContractsPostResponse_additionalContacts
    from .contracts_post_response_recipients import ContractsPostResponse_recipients

@dataclass
class ContractsPostResponse(Parsable):
    # Not relevant
    additional_contacts: Optional[list[ContractsPostResponse_additionalContacts]] = None
    # The date and time of contract approval, in ISO 8601 format.
    approved_at: Optional[str] = None
    # The date and time of the contract award, in ISO 8601 format.
    awarded_at: Optional[str] = None
    # The code of the contract.Max length: 255
    code: Optional[str] = None
    # Not relevant
    company_e_r_p_id: Optional[str] = None
    # The ID of a company managed by a BIM 360 Admin. Detailed company information can be retrieved by calling `GET projects/:project_id/companies <en/docs/bim360/v1/reference/http/projects-:project_id-companies-GET/>`_ and locating the `member_group_id` in the response.
    company_id: Optional[str] = None
    # Not relevant
    company_tax_id: Optional[str] = None
    # The unique ID (UUID) of the company in this account. Detailed company information can be retrieved using this UUID by calling `GET companies/:company_id <en/docs/bim360/v1/reference/http/companies-:company_id-GET/>`_ in the response.
    company_uid: Optional[str] = None
    # The completed work retention percentage of the contract amount.
    completed_work_retention_percent: Optional[float] = None
    # The unique identifier of the default contact for the supplier. This ID is generated and managed by the BIM 360 Admin service. The ``contactId`` can be used to query user information such as ``email`` and ``company``.
    contact_id: Optional[str] = None
    # The code of the currency specified for the contract if it's awarded in a foreign currency.
    currency: Optional[str] = None
    # The detailed description of a contract.Max length: 2048
    description: Optional[str] = None
    # The final exchange rate for the specified ``currency``, applied as a multiplier of the contract's base currency. For example, 1 base currency = 0.7455 foreign currency.
    exchange_rate: Optional[float] = None
    # The date and time of contract execution, in ISO 8601 format.
    executed_at: 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 forecast exchange rate. Default value: ``null``.
    forecast_exchange_rate: Optional[float] = None
    # The last time that the forecast exchange rate was updated, in ISO 8601 format.
    forecast_exchange_rate_updated_at: Optional[datetime.datetime] = 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
    # Not relevant
    internal_id: Optional[str] = None
    # Not relevant
    internal_system: 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 ID of the main contract with which this item is associated.
    main_contract_id: Optional[str] = None
    # The materials retention percentage of the contract amount.
    materials_retention_percent: Optional[float] = None
    # The name of the contract.Max length: 1024
    name: Optional[str] = None
    # The date and time of job completion by the supplier, in ISO 8601 format.
    offsite_at: Optional[str] = None
    # The date and time of the supplier's arrival on-site, in ISO 8601 format.
    onsite_at: Optional[str] = None
    # The user responsible for the purchase. This is the ID of a user managed by BIM 360 Admin.
    owner_id: Optional[str] = None
    # The date and time of purchase, in ISO 8601 format. This is designed for Purchase Order contracts.
    procured_at: Optional[str] = None
    # Not relevant
    recipients: Optional[list[ContractsPostResponse_recipients]] = None
    # The date and time of the supplier's response, in ISO 8601 format.
    responded_at: Optional[str] = None
    # The date and time by which the supplier response is due, in ISO 8601 format.
    response_due: Optional[str] = None
    # The maximum percentage of the total contract amount which can be used as the retention amount.
    retention_cap: Optional[float] = None
    # The date and time of the signed contract return, in ISO 8601 format.
    returned_at: Optional[str] = None
    # The date and time of contract transmission to the supplier, in ISO 8601 format.
    sent_at: Optional[str] = None
    # The user who signed the contract. This is the ID of a user managed by BIM 360 Admin.
    signed_by: Optional[str] = None
    # The URN of the source entity from which the contract is created.
    source: Optional[str] = None
    # The status of this contract.Possible values: ``draft``, ``pending``, ``submitted``, ``revise``, ``sent``, ``signed``, ``executed``, ``closed``, ``inReview``
    status: Optional[str] = None
    # The date and time of the last status change, in ISO 8601 format.
    status_changed_at: Optional[datetime.datetime] = None
    # The subStatus is used when the contract is in an ``executed`` state and may have additional statuses under it. For example, if a contract is ``executed`` but requires the supplier to provide additional information, the status will be executed and the subStatus will be pending. In other cases, subStatus is always ``null``. Possible values: ``null``, ``pending``, ``submitted``, ``revise``. Default value: ``null``.
    sub_status: Optional[str] = None
    # The type of contract. For example, ``consultant`` or ``purchase order``. The ``type`` can be customized by the project admin.
    type: Optional[str] = None
    
    @staticmethod
    def create_from_discriminator_value(parse_node: ParseNode) -> ContractsPostResponse:
        """
        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: ContractsPostResponse
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return ContractsPostResponse()
    
    def get_field_deserializers(self,) -> dict[str, Callable[[ParseNode], None]]:
        """
        The deserialization information for the current model
        Returns: dict[str, Callable[[ParseNode], None]]
        """
        from .contracts_post_response_additional_contacts import ContractsPostResponse_additionalContacts
        from .contracts_post_response_recipients import ContractsPostResponse_recipients

        from .contracts_post_response_additional_contacts import ContractsPostResponse_additionalContacts
        from .contracts_post_response_recipients import ContractsPostResponse_recipients

        fields: dict[str, Callable[[Any], None]] = {
            "additionalContacts": lambda n : setattr(self, 'additional_contacts', n.get_collection_of_object_values(ContractsPostResponse_additionalContacts)),
            "approvedAt": lambda n : setattr(self, 'approved_at', n.get_str_value()),
            "awardedAt": lambda n : setattr(self, 'awarded_at', n.get_str_value()),
            "code": lambda n : setattr(self, 'code', n.get_str_value()),
            "companyERPId": lambda n : setattr(self, 'company_e_r_p_id', n.get_str_value()),
            "companyId": lambda n : setattr(self, 'company_id', n.get_str_value()),
            "companyTaxId": lambda n : setattr(self, 'company_tax_id', n.get_str_value()),
            "companyUid": lambda n : setattr(self, 'company_uid', n.get_str_value()),
            "completedWorkRetentionPercent": lambda n : setattr(self, 'completed_work_retention_percent', n.get_float_value()),
            "contactId": lambda n : setattr(self, 'contact_id', n.get_str_value()),
            "currency": lambda n : setattr(self, 'currency', n.get_str_value()),
            "description": lambda n : setattr(self, 'description', n.get_str_value()),
            "exchangeRate": lambda n : setattr(self, 'exchange_rate', n.get_float_value()),
            "executedAt": lambda n : setattr(self, 'executed_at', 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()),
            "forecastExchangeRate": lambda n : setattr(self, 'forecast_exchange_rate', n.get_float_value()),
            "forecastExchangeRateUpdatedAt": lambda n : setattr(self, 'forecast_exchange_rate_updated_at', n.get_datetime_value()),
            "integrationState": lambda n : setattr(self, 'integration_state', n.get_str_value()),
            "internalId": lambda n : setattr(self, 'internal_id', n.get_str_value()),
            "internalSystem": lambda n : setattr(self, 'internal_system', n.get_str_value()),
            "lastSyncTime": lambda n : setattr(self, 'last_sync_time', n.get_datetime_value()),
            "mainContractId": lambda n : setattr(self, 'main_contract_id', n.get_str_value()),
            "materialsRetentionPercent": lambda n : setattr(self, 'materials_retention_percent', n.get_float_value()),
            "name": lambda n : setattr(self, 'name', n.get_str_value()),
            "offsiteAt": lambda n : setattr(self, 'offsite_at', n.get_str_value()),
            "onsiteAt": lambda n : setattr(self, 'onsite_at', n.get_str_value()),
            "ownerId": lambda n : setattr(self, 'owner_id', n.get_str_value()),
            "procuredAt": lambda n : setattr(self, 'procured_at', n.get_str_value()),
            "recipients": lambda n : setattr(self, 'recipients', n.get_collection_of_object_values(ContractsPostResponse_recipients)),
            "respondedAt": lambda n : setattr(self, 'responded_at', n.get_str_value()),
            "responseDue": lambda n : setattr(self, 'response_due', n.get_str_value()),
            "retentionCap": lambda n : setattr(self, 'retention_cap', n.get_float_value()),
            "returnedAt": lambda n : setattr(self, 'returned_at', n.get_str_value()),
            "sentAt": lambda n : setattr(self, 'sent_at', n.get_str_value()),
            "signedBy": lambda n : setattr(self, 'signed_by', n.get_str_value()),
            "source": lambda n : setattr(self, 'source', n.get_str_value()),
            "status": lambda n : setattr(self, 'status', n.get_str_value()),
            "statusChangedAt": lambda n : setattr(self, 'status_changed_at', n.get_datetime_value()),
            "subStatus": lambda n : setattr(self, 'sub_status', n.get_str_value()),
            "type": lambda n : setattr(self, 'type', n.get_str_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_collection_of_object_values("additionalContacts", self.additional_contacts)
        writer.write_str_value("approvedAt", self.approved_at)
        writer.write_str_value("awardedAt", self.awarded_at)
        writer.write_str_value("code", self.code)
        writer.write_str_value("companyERPId", self.company_e_r_p_id)
        writer.write_str_value("companyId", self.company_id)
        writer.write_str_value("companyTaxId", self.company_tax_id)
        writer.write_str_value("companyUid", self.company_uid)
        writer.write_float_value("completedWorkRetentionPercent", self.completed_work_retention_percent)
        writer.write_str_value("contactId", self.contact_id)
        writer.write_str_value("currency", self.currency)
        writer.write_str_value("description", self.description)
        writer.write_float_value("exchangeRate", self.exchange_rate)
        writer.write_str_value("executedAt", self.executed_at)
        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("forecastExchangeRate", self.forecast_exchange_rate)
        writer.write_datetime_value("forecastExchangeRateUpdatedAt", self.forecast_exchange_rate_updated_at)
        writer.write_str_value("integrationState", self.integration_state)
        writer.write_str_value("internalId", self.internal_id)
        writer.write_str_value("internalSystem", self.internal_system)
        writer.write_datetime_value("lastSyncTime", self.last_sync_time)
        writer.write_str_value("mainContractId", self.main_contract_id)
        writer.write_float_value("materialsRetentionPercent", self.materials_retention_percent)
        writer.write_str_value("name", self.name)
        writer.write_str_value("offsiteAt", self.offsite_at)
        writer.write_str_value("onsiteAt", self.onsite_at)
        writer.write_str_value("ownerId", self.owner_id)
        writer.write_str_value("procuredAt", self.procured_at)
        writer.write_collection_of_object_values("recipients", self.recipients)
        writer.write_str_value("respondedAt", self.responded_at)
        writer.write_str_value("responseDue", self.response_due)
        writer.write_float_value("retentionCap", self.retention_cap)
        writer.write_str_value("returnedAt", self.returned_at)
        writer.write_str_value("sentAt", self.sent_at)
        writer.write_str_value("signedBy", self.signed_by)
        writer.write_str_value("source", self.source)
        writer.write_str_value("status", self.status)
        writer.write_datetime_value("statusChangedAt", self.status_changed_at)
        writer.write_str_value("subStatus", self.sub_status)
        writer.write_str_value("type", self.type)
    

