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.with_node_item_request_builder import WithNodeItemRequestBuilder
    from .nodes_get_response import NodesGetResponse
    from .nodes_post_request_body import NodesPostRequestBody
    from .nodes_post_response import NodesPostResponse
    from .post_insert_option_query_parameter_type import PostInsertOptionQueryParameterType

class NodesRequestBuilder(BaseRequestBuilder):
    """
    Builds and executes requests for operations under /construction/locations/v2/projects/{projectId}/trees/{treeId}/nodes
    """
    def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[str, dict[str, Any]]) -> None:
        """
        Instantiates a new NodesRequestBuilder 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}/construction/locations/v2/projects/{projectId}/trees/{treeId}/nodes{?filter%5Bid%5D*,insertOption*,limit*,offset*,targetNodeId*}", path_parameters)
    
    def by_node_id(self,node_id: UUID) -> WithNodeItemRequestBuilder:
        """
        Gets an item from the Autodesk.ACC.construction.locations.v2.projects.item.trees.item.nodes.item collection
        param node_id: The unique identifier of an LBS node.To find node IDs, call the `GET nodes </en/docs/acc/v1/reference/http/locations-nodes-GET/>`_ endpoint and check the value of ``results.id`` in the returned nodes.
        Returns: WithNodeItemRequestBuilder
        """
        if node_id is None:
            raise TypeError("node_id cannot be null.")
        from .item.with_node_item_request_builder import WithNodeItemRequestBuilder

        url_tpl_params = get_path_parameters(self.path_parameters)
        url_tpl_params["nodeId"] = node_id
        return WithNodeItemRequestBuilder(self.request_adapter, url_tpl_params)
    
    async def get(self,request_configuration: Optional[RequestConfiguration[NodesRequestBuilderGetQueryParameters]] = None) -> Optional[NodesGetResponse]:
        """
        Retrieves an array of nodes (locations) from the specified locations tree (LBS). Returns all nodes in the tree by default.
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[NodesGetResponse]
        """
        request_info = self.to_get_request_information(
            request_configuration
        )
        if not self.request_adapter:
            raise Exception("Http core is null") 
        from .nodes_get_response import NodesGetResponse

        return await self.request_adapter.send_async(request_info, NodesGetResponse, None)
    
    async def post(self,body: NodesPostRequestBody, request_configuration: Optional[RequestConfiguration[NodesRequestBuilderPostQueryParameters]] = None) -> Optional[NodesPostResponse]:
        """
        Creates a node in the specified locations tree. Note that creating the root node is not allowed because the root node is created automatically when the project is created.
        param body: The request body
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[NodesPostResponse]
        """
        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 .nodes_post_response import NodesPostResponse

        return await self.request_adapter.send_async(request_info, NodesPostResponse, None)
    
    def to_get_request_information(self,request_configuration: Optional[RequestConfiguration[NodesRequestBuilderGetQueryParameters]] = None) -> RequestInformation:
        """
        Retrieves an array of nodes (locations) from the specified locations tree (LBS). Returns all nodes in the tree by default.
        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: NodesPostRequestBody, request_configuration: Optional[RequestConfiguration[NodesRequestBuilderPostQueryParameters]] = None) -> RequestInformation:
        """
        Creates a node in the specified locations tree. Note that creating the root node is not allowed because the root node is created automatically when the project is created.
        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) -> NodesRequestBuilder:
        """
        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: NodesRequestBuilder
        """
        if raw_url is None:
            raise TypeError("raw_url cannot be null.")
        return NodesRequestBuilder(self.request_adapter, raw_url)
    
    @dataclass
    class NodesRequestBuilderGetQueryParameters():
        """
        Retrieves an array of nodes (locations) from the specified locations tree (LBS). Returns all nodes in the tree by default.
        """
        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 == "filterid":
                return "filter%5Bid%5D"
            if original_name == "limit":
                return "limit"
            if original_name == "offset":
                return "offset"
            return original_name
        
        # Specifies one or more nodes (locations) in the LBS tree to retrieve. Separate multiple node IDs with commas (no space); for example, ``filter[id]=88e07ccb-4594-4dc5-8973-304412b8fa96,de9aca33-5e0c-4668-85fa-f96273db4b35``.To find node IDs, call this endpoint and check the value of ``results.id`` in the returned nodes.Note that when you use this parameter, the server ignores the ``limit`` and ``offset`` parameters, and each node in the response includes a ``path`` array containing its ancestor nodes in the tree.
        filterid: Optional[list[str]] = None

        # The maximum number of location nodes to return per page. Acceptable values: ``1-10000``. Default value: ``10000``.
        limit: Optional[int] = None

        # The node index at which the pagination starts. This is zero-based; for example, with a value of ``6``, the response starts with the seventh node.
        offset: Optional[int] = None

    
    @dataclass
    class NodesRequestBuilderGetRequestConfiguration(RequestConfiguration[NodesRequestBuilderGetQueryParameters]):
        """
        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 NodesRequestBuilderPostQueryParameters():
        """
        Creates a node in the specified locations tree. Note that creating the root node is not allowed because the root node is created automatically when the project is created.
        """
        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 == "insert_option":
                return "insertOption"
            if original_name == "target_node_id":
                return "targetNodeId"
            return original_name
        
        # Where to insert the new node relative to the target node that you specified with ``targetNodeId``. The nodes in a given tier of the tree have a defined sequence order, and ``insertOption`` specifies whether the new node comes before or after the target node.Required only when ``targetNodeId`` is also included in the request.Possible values: ``After``, ``Before``
        insert_option: Optional[PostInsertOptionQueryParameterType] = None

        # Unique identifier of a node that will be the new node's immediate sibling in the locations tree. The target node's ``parentId`` must match the ``body.parentId`` field in the request.Note that nodes in a given tier of the tree have a defined sequence order. The new node will be created in the same tier, either before or after the target node. You specify the sequence position of the new node using the  ``insertOption`` parameter.Note that this parameter is unavailable if this request is creating an existing node's first child node.Required only when ``insertOption`` is also included in the request.
        target_node_id: Optional[UUID] = None

    
    @dataclass
    class NodesRequestBuilderPostRequestConfiguration(RequestConfiguration[NodesRequestBuilderPostQueryParameters]):
        """
        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)
    

