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 .get_filter_type_query_parameter_type import GetFilterTypeQueryParameterType
    from .item.with_sub_cost_items_item_request_builder import WithSubCostItemsItemRequestBuilder
    from .sub_cost_items_get_response import SubCostItemsGetResponse
    from .sub_cost_items_post_request_body import SubCostItemsPostRequestBody
    from .sub_cost_items_post_response import SubCostItemsPostResponse

class SubCostItemsRequestBuilder(BaseRequestBuilder):
    """
    Builds and executes requests for operations under /cost/v1/containers/{containerId}/cost-items/{costItemId}/sub-cost-items
    """
    def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[str, dict[str, Any]]) -> None:
        """
        Instantiates a new SubCostItemsRequestBuilder 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}/cost-items/{costItemId}/sub-cost-items{?filter%5Btype%5D*,limit*,offset*,sort*}", path_parameters)
    
    def by_sub_cost_items_id(self,sub_cost_items_id: UUID) -> WithSubCostItemsItemRequestBuilder:
        """
        Gets an item from the Autodesk.ACC.cost.v1.containers.item.costItems.item.subCostItems.item collection
        param sub_cost_items_id: The ID of the sub cost item to be updated. To find the sub cost item ID, call `GET sub-cost-items </en/docs/bim360/v1/reference/http/cost-sub-cost-items-GET/>`_.
        Returns: WithSubCostItemsItemRequestBuilder
        """
        if sub_cost_items_id is None:
            raise TypeError("sub_cost_items_id cannot be null.")
        from .item.with_sub_cost_items_item_request_builder import WithSubCostItemsItemRequestBuilder

        url_tpl_params = get_path_parameters(self.path_parameters)
        url_tpl_params["subCostItemsId"] = sub_cost_items_id
        return WithSubCostItemsItemRequestBuilder(self.request_adapter, url_tpl_params)
    
    async def get(self,request_configuration: Optional[RequestConfiguration[SubCostItemsRequestBuilderGetQueryParameters]] = None) -> Optional[SubCostItemsGetResponse]:
        """
        Retrieves sub cost items associated with a specific cost item in a project.
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[SubCostItemsGetResponse]
        """
        request_info = self.to_get_request_information(
            request_configuration
        )
        if not self.request_adapter:
            raise Exception("Http core is null") 
        from .sub_cost_items_get_response import SubCostItemsGetResponse

        return await self.request_adapter.send_async(request_info, SubCostItemsGetResponse, None)
    
    async def post(self,body: SubCostItemsPostRequestBody, request_configuration: Optional[RequestConfiguration[QueryParameters]] = None) -> Optional[SubCostItemsPostResponse]:
        """
        Creates a sub cost item within a specific cost item in a project. Sub cost items store detailed cost breakdowns and can be used for tracking and categorization.
        param body: The request body
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[SubCostItemsPostResponse]
        """
        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 .sub_cost_items_post_response import SubCostItemsPostResponse

        return await self.request_adapter.send_async(request_info, SubCostItemsPostResponse, None)
    
    def to_get_request_information(self,request_configuration: Optional[RequestConfiguration[SubCostItemsRequestBuilderGetQueryParameters]] = None) -> RequestInformation:
        """
        Retrieves sub cost items associated with a specific cost item in a project.
        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: SubCostItemsPostRequestBody, request_configuration: Optional[RequestConfiguration[QueryParameters]] = None) -> RequestInformation:
        """
        Creates a sub cost item within a specific cost item in a project. Sub cost items store detailed cost breakdowns and can be used for tracking and categorization.
        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) -> SubCostItemsRequestBuilder:
        """
        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: SubCostItemsRequestBuilder
        """
        if raw_url is None:
            raise TypeError("raw_url cannot be null.")
        return SubCostItemsRequestBuilder(self.request_adapter, raw_url)
    
    @dataclass
    class SubCostItemsRequestBuilderGetQueryParameters():
        """
        Retrieves sub cost items associated with a specific cost item in a project.
        """
        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 == "filtertype":
                return "filter%5Btype%5D"
            if original_name == "limit":
                return "limit"
            if original_name == "offset":
                return "offset"
            if original_name == "sort":
                return "sort"
            return original_name
        
        # The type of the value to break down.Possible values: ``estimated``, ``proposed``, ``submitted``, ``approved``, ``committed``
        filtertype: Optional[GetFilterTypeQueryParameterType] = 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 SubCostItemsRequestBuilderGetRequestConfiguration(RequestConfiguration[SubCostItemsRequestBuilderGetQueryParameters]):
        """
        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 SubCostItemsRequestBuilderPostRequestConfiguration(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)
    

