from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass, field
from kiota_abstractions.base_request_builder import BaseRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from kiota_abstractions.default_query_parameters import QueryParameters
from kiota_abstractions.get_path_parameters import get_path_parameters
from kiota_abstractions.method import Method
from kiota_abstractions.request_adapter import RequestAdapter
from kiota_abstractions.request_information import RequestInformation
from kiota_abstractions.request_option import RequestOption
from kiota_abstractions.serialization import Parsable, ParsableFactory
from typing import Any, Optional, TYPE_CHECKING, Union
from uuid import UUID
from warnings import warn

if TYPE_CHECKING:
    from .item.change_order_item_request_builder import ChangeOrderItemRequestBuilder
    from .with_change_order_get_response import WithChangeOrderGetResponse
    from .with_change_order_post_request_body import WithChangeOrderPostRequestBody
    from .with_change_order_post_response import WithChangeOrderPostResponse

class WithChangeOrderItemRequestBuilder(BaseRequestBuilder):
    """
    Builds and executes requests for operations under /cost/v1/containers/{containerId}/change-orders/{changeOrder}
    """
    def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[str, dict[str, Any]]) -> None:
        """
        Instantiates a new WithChangeOrderItemRequestBuilder and sets the default values.
        param path_parameters: The raw url or the url-template parameters for the request.
        param request_adapter: The request adapter to use to execute the requests.
        Returns: None
        """
        super().__init__(request_adapter, "{+baseurl}/cost/v1/containers/{containerId}/change-orders/{changeOrder}{?filter%5BbudgetStatus%5D*,filter%5BcontractId%5D*,filter%5BcostStatus%5D*,filter%5BexternalId%5D*,filter%5BexternalSystem%5D*,filter%5Bid%5D*,filter%5BlastModifiedSince%5D*,filter%5BmainContractId%5D*,filter%5Bnumber%5D*,filter%5BsourceId%5D*,include*,limit*,offset*,sort*}", path_parameters)
    
    def by_id(self,id: UUID) -> ChangeOrderItemRequestBuilder:
        """
        Gets an item from the Autodesk.ACC.cost.v1.containers.item.changeOrders.item.item collection
        param id: The change order's ID.
        Returns: ChangeOrderItemRequestBuilder
        """
        if id is None:
            raise TypeError("id cannot be null.")
        from .item.change_order_item_request_builder import ChangeOrderItemRequestBuilder

        url_tpl_params = get_path_parameters(self.path_parameters)
        url_tpl_params["id"] = id
        return ChangeOrderItemRequestBuilder(self.request_adapter, url_tpl_params)
    
    async def get(self,request_configuration: Optional[RequestConfiguration[WithChangeOrderItemRequestBuilderGetQueryParameters]] = None) -> Optional[WithChangeOrderGetResponse]:
        """
        Note that requests for change order (RCO) may be referred to as ``change order requests`` (COR) in some Construction Cloud contexts. These two terms are interchangeable.
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[WithChangeOrderGetResponse]
        """
        request_info = self.to_get_request_information(
            request_configuration
        )
        if not self.request_adapter:
            raise Exception("Http core is null") 
        from .with_change_order_get_response import WithChangeOrderGetResponse

        return await self.request_adapter.send_async(request_info, WithChangeOrderGetResponse, None)
    
    async def post(self,body: WithChangeOrderPostRequestBody, request_configuration: Optional[RequestConfiguration[QueryParameters]] = None) -> Optional[WithChangeOrderPostResponse]:
        """
        Create a new change order (typically a PCO) to initiate a change.
        param body: The request body
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[WithChangeOrderPostResponse]
        """
        if body is None:
            raise TypeError("body cannot be null.")
        request_info = self.to_post_request_information(
            body, request_configuration
        )
        if not self.request_adapter:
            raise Exception("Http core is null") 
        from .with_change_order_post_response import WithChangeOrderPostResponse

        return await self.request_adapter.send_async(request_info, WithChangeOrderPostResponse, None)
    
    def to_get_request_information(self,request_configuration: Optional[RequestConfiguration[WithChangeOrderItemRequestBuilderGetQueryParameters]] = None) -> RequestInformation:
        """
        Note that requests for change order (RCO) may be referred to as ``change order requests`` (COR) in some Construction Cloud contexts. These two terms are interchangeable.
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: RequestInformation
        """
        request_info = RequestInformation(Method.GET, self.url_template, self.path_parameters)
        request_info.configure(request_configuration)
        request_info.headers.try_add("Accept", "application/json")
        return request_info
    
    def to_post_request_information(self,body: WithChangeOrderPostRequestBody, request_configuration: Optional[RequestConfiguration[QueryParameters]] = None) -> RequestInformation:
        """
        Create a new change order (typically a PCO) to initiate a change.
        param body: The request body
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: RequestInformation
        """
        if body is None:
            raise TypeError("body cannot be null.")
        request_info = RequestInformation(Method.POST, self.url_template, self.path_parameters)
        request_info.configure(request_configuration)
        request_info.headers.try_add("Accept", "application/json")
        request_info.set_content_from_parsable(self.request_adapter, "application/json", body)
        return request_info
    
    def with_url(self,raw_url: str) -> WithChangeOrderItemRequestBuilder:
        """
        Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored.
        param raw_url: The raw URL to use for the request builder.
        Returns: WithChangeOrderItemRequestBuilder
        """
        if raw_url is None:
            raise TypeError("raw_url cannot be null.")
        return WithChangeOrderItemRequestBuilder(self.request_adapter, raw_url)
    
    @dataclass
    class WithChangeOrderItemRequestBuilderGetQueryParameters():
        """
        Note that requests for change order (RCO) may be referred to as ``change order requests`` (COR) in some Construction Cloud contexts. These two terms are interchangeable.
        """
        def get_query_parameter(self,original_name: str) -> str:
            """
            Maps the query parameters names to their encoded names for the URI template parsing.
            param original_name: The original query parameter name in the class.
            Returns: str
            """
            if original_name is None:
                raise TypeError("original_name cannot be null.")
            if original_name == "filterbudget_status":
                return "filter%5BbudgetStatus%5D"
            if original_name == "filtercontract_id":
                return "filter%5BcontractId%5D"
            if original_name == "filtercost_status":
                return "filter%5BcostStatus%5D"
            if original_name == "filterexternal_id":
                return "filter%5BexternalId%5D"
            if original_name == "filterexternal_system":
                return "filter%5BexternalSystem%5D"
            if original_name == "filterid":
                return "filter%5Bid%5D"
            if original_name == "filterlast_modified_since":
                return "filter%5BlastModifiedSince%5D"
            if original_name == "filtermain_contract_id":
                return "filter%5BmainContractId%5D"
            if original_name == "filternumber":
                return "filter%5Bnumber%5D"
            if original_name == "filtersource_id":
                return "filter%5BsourceId%5D"
            if original_name == "include":
                return "include"
            if original_name == "limit":
                return "limit"
            if original_name == "offset":
                return "offset"
            if original_name == "sort":
                return "sort"
            return original_name
        
        # Returns only the items that are linked to budgets that have the specified status codes. Separate multiple codes with commas. For example, ``filter[budgetStatus]=draft,open``.  Possible values ``draft``, ``open``, ``submitted``, ``accepted``, ``approved``, ``executed``, ``rejected``. For more information about cost item budget statuses, see `Cost Item Statuses <https://help.autodesk.com/view/BUILD/ENU/?guid=Cost_Change_Order_Statuses#cost-item-statuses>`_.
        filterbudget_status: Optional[list[str]] = None

        # Returns only items associated with the contracts identified on this list of IDs. Separate multiple IDs with commas; for example:``filter[contractId]=id1,id2``.You can also provide a value of ``blank`` to return items that are not linked to any contract; for example:``filter[contractId]=blank``.
        filtercontract_id: Optional[list[str]] = None

        # Returns only the items that have the specified status codes. Separate multiple codes with commas. For example, ``filter[budgetStatus]=draft,open``.  Possible values ``draft``, ``open``, ``pricing``, ``proposed``, ``accepted``, ``approved``, ``executed``, ``rejected``. For more information about cost item cost statuses, see `Cost Item Statuses <https://help.autodesk.com/view/BUILD/ENU/?guid=Cost_Change_Order_Statuses#cost-item-statuses>`_.
        filtercost_status: Optional[list[str]] = None

        # The ID of the item in the external ERP system. Use this ID to track or look up data in an integrated ERP system. For example, ``filter[externalId]=id1,id2``.
        filterexternal_id: Optional[list[str]] = None

        # The name of the external ERP system. Use this name to identify or search within the integrated system. For example, ``filter[externalSystem]=Sage300``.Max length: 255
        filterexternal_system: Optional[str] = None

        # Returns only the items that are identified by the provided list of item IDs. Separate multiple IDs with commas. For example, ``filter[id]=id1,id2``.
        filterid: Optional[list[str]] = None

        # Returns only items that were modified since the specified date and time, in ISO 8601 format. For example, ``filter[lastModifiedSince]=2020-03-01T13:00:00Z``.
        filterlast_modified_since: Optional[str] = None

        # The Main Contract ID. Separate multiple IDs with commas. For example, ``filter[mainContractId]=id1,id2``, or filter these items that are not linked to any main contract  ``filter[mainContractId]=blank``.
        filtermain_contract_id: Optional[list[str]] = None

        # Returns only the items that are identified by the provided list of auto-generated sequence numbers. Separate multiple numbers with commas; for example, ``filter[number]=0001,0002``.
        filternumber: Optional[list[str]] = None

        # Returns only change orders that were generated from the PCO with the provided ID, in UUID format.
        filtersource_id: Optional[UUID] = None

        # Include nested resources in the response. For example, ``include=costItems`` will return the related cost items with the change order. ``include=attributes`` will return custom attributes which represents the ``properties`` in the response. Possible values: ``costItems``, ``costItems[changeOrders]``, ``attributes``, ``comments``.
        include: Optional[list[str]] = None

        # The maximum number of records returned per page. Default: ``100``. A page may contain fewer records than the limit if there are fewer matching items or if it is the last page of results.
        limit: Optional[int] = None

        # The number of records to skip before returning results. Used together with ``limit`` to paginate through results, where ``offset`` specifies the starting point and ``limit`` specifies the number of records to return.
        offset: Optional[int] = None

        # Defines the sort order for the results. Each attribute can be sorted in ``asc`` (default) or ``desc`` order. For example, ``sort=name desc`` sorts the results by name in descending order.
        sort: Optional[str] = None

    
    @dataclass
    class WithChangeOrderItemRequestBuilderGetRequestConfiguration(RequestConfiguration[WithChangeOrderItemRequestBuilderGetQueryParameters]):
        """
        Configuration for the request such as headers, query parameters, and middleware options.
        """
        warn("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.", DeprecationWarning)
    
    @dataclass
    class WithChangeOrderItemRequestBuilderPostRequestConfiguration(RequestConfiguration[QueryParameters]):
        """
        Configuration for the request such as headers, query parameters, and middleware options.
        """
        warn("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.", DeprecationWarning)
    

