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 .attachments_get_response import AttachmentsGetResponse
    from .attachments_post_request_body import AttachmentsPostRequestBody
    from .attachments_post_response import AttachmentsPostResponse
    from .item.with_attachment_item_request_builder import WithAttachmentItemRequestBuilder

class AttachmentsRequestBuilder(BaseRequestBuilder):
    """
    Builds and executes requests for operations under /construction/submittals/v2/projects/{projectId}/items/{itemId}/attachments
    """
    def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[str, dict[str, Any]]) -> None:
        """
        Instantiates a new AttachmentsRequestBuilder 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/submittals/v2/projects/{projectId}/items/{itemId}/attachments{?filter%5BcategoryId%5D*,filter%5BisFileUploaded%5D*,filter%5Brevision%5D*,limit*,offset*,sort*}", path_parameters)
    
    def by_attachment_id(self,attachment_id: str) -> WithAttachmentItemRequestBuilder:
        """
        Gets an item from the Autodesk.ACC.construction.submittals.v2.projects.item.items.item.attachments.item collection
        param attachment_id: The ID of the attachment. To find the ID, call `GET attachments </en/docs/acc/v1/reference/http/submittals-items-itemId-attachments-GET/>`_.
        Returns: WithAttachmentItemRequestBuilder
        """
        if attachment_id is None:
            raise TypeError("attachment_id cannot be null.")
        from .item.with_attachment_item_request_builder import WithAttachmentItemRequestBuilder

        url_tpl_params = get_path_parameters(self.path_parameters)
        url_tpl_params["attachmentId"] = attachment_id
        return WithAttachmentItemRequestBuilder(self.request_adapter, url_tpl_params)
    
    async def get(self,request_configuration: Optional[RequestConfiguration[AttachmentsRequestBuilderGetQueryParameters]] = None) -> Optional[AttachmentsGetResponse]:
        """
        Retrieves attachments for a specified submittal item. Note that this endpoint is not compatible with BIM 360 projects.
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[AttachmentsGetResponse]
        """
        request_info = self.to_get_request_information(
            request_configuration
        )
        if not self.request_adapter:
            raise Exception("Http core is null") 
        from .attachments_get_response import AttachmentsGetResponse

        return await self.request_adapter.send_async(request_info, AttachmentsGetResponse, None)
    
    async def post(self,body: AttachmentsPostRequestBody, request_configuration: Optional[RequestConfiguration[QueryParameters]] = None) -> Optional[AttachmentsPostResponse]:
        """
        Adds an attachment to a submittal item within a project. This allows users to include relevant files as part of the submittal process.
        param body: The request body
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[AttachmentsPostResponse]
        """
        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 .attachments_post_response import AttachmentsPostResponse

        return await self.request_adapter.send_async(request_info, AttachmentsPostResponse, None)
    
    def to_get_request_information(self,request_configuration: Optional[RequestConfiguration[AttachmentsRequestBuilderGetQueryParameters]] = None) -> RequestInformation:
        """
        Retrieves attachments for a specified submittal item. Note that this endpoint is not compatible with BIM 360 projects.
        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: AttachmentsPostRequestBody, request_configuration: Optional[RequestConfiguration[QueryParameters]] = None) -> RequestInformation:
        """
        Adds an attachment to a submittal item within a project. This allows users to include relevant files as part of the submittal process.
        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) -> AttachmentsRequestBuilder:
        """
        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: AttachmentsRequestBuilder
        """
        if raw_url is None:
            raise TypeError("raw_url cannot be null.")
        return AttachmentsRequestBuilder(self.request_adapter, raw_url)
    
    @dataclass
    class AttachmentsRequestBuilderGetQueryParameters():
        """
        Retrieves attachments for a specified submittal item. Note that this endpoint is not compatible with BIM 360 projects.
        """
        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 == "filtercategory_id":
                return "filter%5BcategoryId%5D"
            if original_name == "filteris_file_uploaded":
                return "filter%5BisFileUploaded%5D"
            if original_name == "filterrevision":
                return "filter%5Brevision%5D"
            if original_name == "limit":
                return "limit"
            if original_name == "offset":
                return "offset"
            if original_name == "sort":
                return "sort"
            return original_name
        
        # Filter attachments by category identifier. Multiple values can be separated by commas.
        filtercategory_id: Optional[str] = None

        # ``true``: to filter files that are uploaded.``false``: to filter files that are not uploaded.
        filteris_file_uploaded: Optional[str] = None

        # Filter items with the specified revision number. You can specify multiple values. Separate multiple values with commas. For example, ``filter[revision]=1``.
        filterrevision: Optional[str] = None

        # The maximum number of results per page. Possible values: ``1``- ``50``. Default value: ``20``. For example, to limit the response to two results per page, use ``limit=2``.
        limit: Optional[int] = None

        # The number of results to skip before starting to return data. For example, to skip the first 20 results, include ``offset=20`` in the query string. For more details, see the `JSON API Paging Help documentation <https://jsonapi.org/format/#fetching-pagination>`_.
        offset: Optional[int] = None

        # Sort attachments by specific fields in either ascending (``asc``) or descending (``desc``) order. Separate multiple criteria with commas. For example, ``statusId asc``.Possible values: ``id``, ``isFileUploaded``, ``asyncState``, ``createdBy``, ``createdAt``, ``updatedBy``, ``updatedAt``, ``name``, ``uploadUrn``, ``urn``, ``urnPage``, ``resourceUrns``, ``urnTypeId``, ``urnVersion``, ``revision``, ``categoryId``, ``isReview``, ``isResponse``.
        sort: Optional[str] = None

    
    @dataclass
    class AttachmentsRequestBuilderGetRequestConfiguration(RequestConfiguration[AttachmentsRequestBuilderGetQueryParameters]):
        """
        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 AttachmentsRequestBuilderPostRequestConfiguration(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)
    

