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 .companies_get_response import CompaniesGetResponse
    from .get_filter_text_match_query_parameter_type import GetFilterTextMatchQueryParameterType

class CompaniesRequestBuilder(BaseRequestBuilder):
    """
    Builds and executes requests for operations under /construction/admin/v1/accounts/{accountId}/companies
    """
    def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[str, dict[str, Any]]) -> None:
        """
        Instantiates a new CompaniesRequestBuilder 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/admin/v1/accounts/{accountId}/companies{?fields*,filterTextMatch*,filter%5BerpId%5D*,filter%5Bname%5D*,filter%5BtaxId%5D*,filter%5Btrade%5D*,filter%5BupdatedAt%5D*,limit*,offset*,orFilters*,sort*}", path_parameters)
    
    async def get(self,request_configuration: Optional[RequestConfiguration[CompaniesRequestBuilderGetQueryParameters]] = None) -> Optional[CompaniesGetResponse]:
        """
        Returns a list of companies in an account.
        param request_configuration: Configuration for the request such as headers, query parameters, and middleware options.
        Returns: Optional[CompaniesGetResponse]
        """
        request_info = self.to_get_request_information(
            request_configuration
        )
        if not self.request_adapter:
            raise Exception("Http core is null") 
        from .companies_get_response import CompaniesGetResponse

        return await self.request_adapter.send_async(request_info, CompaniesGetResponse, None)
    
    def to_get_request_information(self,request_configuration: Optional[RequestConfiguration[CompaniesRequestBuilderGetQueryParameters]] = None) -> RequestInformation:
        """
        Returns a list of companies in an account.
        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 with_url(self,raw_url: str) -> CompaniesRequestBuilder:
        """
        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: CompaniesRequestBuilder
        """
        if raw_url is None:
            raise TypeError("raw_url cannot be null.")
        return CompaniesRequestBuilder(self.request_adapter, raw_url)
    
    @dataclass
    class CompaniesRequestBuilderGetQueryParameters():
        """
        Returns a list of companies in an account.
        """
        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 == "filtererp_id":
                return "filter%5BerpId%5D"
            if original_name == "filtername":
                return "filter%5Bname%5D"
            if original_name == "filtertax_id":
                return "filter%5BtaxId%5D"
            if original_name == "filtertrade":
                return "filter%5Btrade%5D"
            if original_name == "filterupdated_at":
                return "filter%5BupdatedAt%5D"
            if original_name == "filter_text_match":
                return "filterTextMatch"
            if original_name == "or_filters":
                return "orFilters"
            if original_name == "fields":
                return "fields"
            if original_name == "limit":
                return "limit"
            if original_name == "offset":
                return "offset"
            if original_name == "sort":
                return "sort"
            return original_name
        
        # List of fields to return in the response.  Defaults to all fields.  Valid list of fields are `accountId`, `name`, `trade`, `addresses`, `websiteUrl`, `description`, `erpId`, `taxId`, `imageUrl`, `status`, `createdAt`, `updatedAt`, `projectSize`, `userSize` and `originalName`.
        fields: Optional[list[str]] = None

        # Specifies how text-based filters should match values in supported fields.This parameter can be used in any endpoint that supports text-based filtering (e.g., ``filter[name]``, ``filter[jobNumber]``, ``filter[companyName]``, etc.).Possible values:``contains`` (default) – Matches if the field contains the specified text anywhere``startsWith`` – Matches if the field starts with the specified text``endsWith`` – Matches if the field ends with the specified text``equals`` – Matches only if the field exactly matches the specified textMatching is case-insensitive.Wildcards and regular expressions are not supported.
        filter_text_match: Optional[GetFilterTextMatchQueryParameterType] = None

        # Filter companies by ERP Id.  Can be a partial match based on the value of `filterTextMatch` provided.Max length: 255
        filtererp_id: Optional[str] = None

        # Filter companies by name.  Can be a partial match based on the value of `filterTextMatch` provided.Max length: 255
        filtername: Optional[str] = None

        # Filter companies by tax Id.  Can be a partial match based on the value of `filterTextMatch` provided.Max length: 255
        filtertax_id: Optional[str] = None

        # Filter companies by trade.  Can be a partial match based on the value of `filterTextMatch` provided.Max length: 255
        filtertrade: Optional[str] = None

        # Filter companies by updated at date range. The range must be specified with dates in an ISO-8601 format with time required.  The start and end dates of the range should be separated by `..`  One of the dates in the range may be omitted. For example, to get everything on or before June 1, 2019 the range would be `..2019-06-01T23:59:59.999Z`. To get everything after June 1, 2019 the range would be `2019-06-01T00:00:00.000Z..`.Max length: 100
        filterupdated_at: Optional[str] = None

        # The maximum number of records to return in the response.Default: ``20``Minimum: ``1``Maximum: ``200`` (If a larger value is provided, only 200 records are returned)
        limit: Optional[int] = None

        # The index of the first record to return.Used for pagination in combination with the ``limit`` parameter.Example: ``limit=20`` and ``offset=40`` returns records 41–60.
        offset: Optional[int] = None

        # List of filtered fields to apply an ``or`` operator. Valid list of fields are `erpId`, `name`, `taxId`, `trade`, `updatedAt`.
        or_filters: Optional[list[str]] = None

        # The list of fields to sort by.  When multiple fields are listed the later property is used to sort the resources where the previous fields have the same value. Each property can be followed by a direction modifier of either `asc` (ascending) or `desc` (descending).  If no direction is specified then `asc` is assumed.  Valid fields for sorting are `name`, `trade`, `erpId`, `taxId`, `status`, `createdAt`, `updatedAt`, `projectSize` and `userSize`.  Default sort is `name`.
        sort: Optional[list[str]] = None

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

