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 warnings import warn

if TYPE_CHECKING:
    from .categories_get_response import CategoriesGetResponse
    from .categories_post_request_body import CategoriesPostRequestBody
    from .categories_post_response import CategoriesPostResponse
    from .item.with_category_item_request_builder import WithCategoryItemRequestBuilder

class CategoriesRequestBuilder(BaseRequestBuilder):
    """
    Builds and executes requests for operations under /construction/assets/v1/projects/{projectId}/categories
    """
    def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[str, dict[str, Any]]) -> None:
        """
        Instantiates a new CategoriesRequestBuilder 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/assets/v1/projects/{projectId}/categories{?filter%5BisActive%5D*,filter%5BmaxDepth%5D*,filter%5BparentId%5D*,filter%5BupdatedAt%5D*,includeUid*}", path_parameters)
    
    def by_category_id(self,category_id: str) -> WithCategoryItemRequestBuilder:
        """
        Gets an item from the Autodesk.ACC.construction.assets.v1.projects.item.categories.item collection
        param category_id: The category ID
        Returns: WithCategoryItemRequestBuilder
        """
        if category_id is None:
            raise TypeError("category_id cannot be null.")
        from .item.with_category_item_request_builder import WithCategoryItemRequestBuilder

        url_tpl_params = get_path_parameters(self.path_parameters)
        url_tpl_params["categoryId"] = category_id
        return WithCategoryItemRequestBuilder(self.request_adapter, url_tpl_params)
    
    async def get(self,request_configuration: Optional[RequestConfiguration[CategoriesRequestBuilderGetQueryParameters]] = None) -> Optional[CategoriesGetResponse]:
        """
        GET categories
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[CategoriesGetResponse]
        """
        request_info = self.to_get_request_information(
            request_configuration
        )
        if not self.request_adapter:
            raise Exception("Http core is null") 
        from .categories_get_response import CategoriesGetResponse

        return await self.request_adapter.send_async(request_info, CategoriesGetResponse, None)
    
    async def post(self,body: CategoriesPostRequestBody, request_configuration: Optional[RequestConfiguration[CategoriesRequestBuilderPostQueryParameters]] = None) -> Optional[CategoriesPostResponse]:
        """
        POST categories
        param body: The request body
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[CategoriesPostResponse]
        """
        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 .categories_post_response import CategoriesPostResponse

        return await self.request_adapter.send_async(request_info, CategoriesPostResponse, None)
    
    def to_get_request_information(self,request_configuration: Optional[RequestConfiguration[CategoriesRequestBuilderGetQueryParameters]] = None) -> RequestInformation:
        """
        GET categories
        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: CategoriesPostRequestBody, request_configuration: Optional[RequestConfiguration[CategoriesRequestBuilderPostQueryParameters]] = None) -> RequestInformation:
        """
        POST categories
        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) -> CategoriesRequestBuilder:
        """
        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: CategoriesRequestBuilder
        """
        if raw_url is None:
            raise TypeError("raw_url cannot be null.")
        return CategoriesRequestBuilder(self.request_adapter, raw_url)
    
    @dataclass
    class CategoriesRequestBuilderGetQueryParameters():
        """
        GET categories
        """
        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 == "filteris_active":
                return "filter%5BisActive%5D"
            if original_name == "filtermax_depth":
                return "filter%5BmaxDepth%5D"
            if original_name == "filterparent_id":
                return "filter%5BparentId%5D"
            if original_name == "filterupdated_at":
                return "filter%5BupdatedAt%5D"
            if original_name == "include_uid":
                return "includeUid"
            return original_name
        
        # Specifies whether or not to return categories that are active. If ``true``, return only active categories. If``false``, return only inactive categories. Default is to return both active and inactive categories, to ensurefull tree structure is returned (conversely, full tree structure is not guaranteed when filtering active orinactive categories).Note that this behavior is different than that of the ``includeDeleted`` flag other endpoints use.
        filteris_active: Optional[bool] = None

        # Specifies the depth of the category tree to return, starting with the root category. Depth ``0`` means to returnonly the root category. Depth ``4``, for example, means to return only the root category and categories that arefour levels of inheritance deep, but not to return categories that are five or more levels deep.Note that this can be used in conjunction with ``filter[parentId]``, but that the depth is still computed fromthe root category, not the parent category specified by the filter.
        filtermax_depth: Optional[float] = None

        # Specifies the parent category ID of returned categories. The query returns only categories that are directchild categories of the specified category.
        filterparent_id: Optional[str] = None

        # A string that specifies a date and time or a date and time range at which all returned objects mast have beenupdated. A single date and time takes this format: ``YYYY-MM-DDThh:mm:ss.SSSZ``, A date and time range takes thisformat: ``YYYY-MM-DDThh:mm:ss.SSSZ..YYYY-MM-DDThh:mm:ss.SSSZ``. Range queries can be closed or open in eitherdirection: ``YYYY-MM-DDThh:mm:ss.SSSZ..`` or ``..YYYY-MM-DDThh:mm:ss.SSSZ``.
        filterupdated_at: Optional[str] = None

        # If provided, and set to ``true``, the globally-unique category ``uid`` field will be present in the response.The globally unique category ID is used with the (upcoming) ``v3`` category APIs. The option to include theglobally-unique ID with the ``v1`` category APIs is to help consumers transition to the new IDs.
        include_uid: Optional[bool] = None

    
    @dataclass
    class CategoriesRequestBuilderGetRequestConfiguration(RequestConfiguration[CategoriesRequestBuilderGetQueryParameters]):
        """
        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 CategoriesRequestBuilderPostQueryParameters():
        """
        POST categories
        """
        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 == "include_uid":
                return "includeUid"
            return original_name
        
        # If provided, and set to ``true``, the globally-unique category ``uid`` field will be present in the response.The globally unique category ID is used with the (upcoming) ``v3`` category APIs. The option to include theglobally-unique ID with the ``v1`` category APIs is to help consumers transition to the new IDs.
        include_uid: Optional[bool] = None

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

