<?php

namespace Microsoft\Graph\Generated\Places;

use Exception;
use Http\Promise\Promise;
use Microsoft\Graph\Generated\Models\ODataErrors\ODataError;
use Microsoft\Graph\Generated\Models\Place;
use Microsoft\Graph\Generated\Places\Count\CountRequestBuilder;
use Microsoft\Graph\Generated\Places\GraphBuilding\GraphBuildingRequestBuilder;
use Microsoft\Graph\Generated\Places\GraphDesk\GraphDeskRequestBuilder;
use Microsoft\Graph\Generated\Places\GraphFloor\GraphFloorRequestBuilder;
use Microsoft\Graph\Generated\Places\GraphRoom\GraphRoomRequestBuilder;
use Microsoft\Graph\Generated\Places\GraphRoomList\GraphRoomListRequestBuilder;
use Microsoft\Graph\Generated\Places\GraphSection\GraphSectionRequestBuilder;
use Microsoft\Graph\Generated\Places\GraphWorkspace\GraphWorkspaceRequestBuilder;
use Microsoft\Graph\Generated\Places\Item\PlaceItemRequestBuilder;
use Microsoft\Kiota\Abstractions\BaseRequestBuilder;
use Microsoft\Kiota\Abstractions\HttpMethod;
use Microsoft\Kiota\Abstractions\RequestAdapter;
use Microsoft\Kiota\Abstractions\RequestInformation;

/**
 * Provides operations to manage the collection of place entities.
*/
class PlacesRequestBuilder extends BaseRequestBuilder 
{
    /**
     * Provides operations to count the resources in the collection.
    */
    public function count(): CountRequestBuilder {
        return new CountRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Casts the previous resource to building.
    */
    public function graphBuilding(): GraphBuildingRequestBuilder {
        return new GraphBuildingRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Casts the previous resource to desk.
    */
    public function graphDesk(): GraphDeskRequestBuilder {
        return new GraphDeskRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Casts the previous resource to floor.
    */
    public function graphFloor(): GraphFloorRequestBuilder {
        return new GraphFloorRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Casts the previous resource to room.
    */
    public function graphRoom(): GraphRoomRequestBuilder {
        return new GraphRoomRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Casts the previous resource to roomList.
    */
    public function graphRoomList(): GraphRoomListRequestBuilder {
        return new GraphRoomListRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Casts the previous resource to section.
    */
    public function graphSection(): GraphSectionRequestBuilder {
        return new GraphSectionRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Casts the previous resource to workspace.
    */
    public function graphWorkspace(): GraphWorkspaceRequestBuilder {
        return new GraphWorkspaceRequestBuilder($this->pathParameters, $this->requestAdapter);
    }
    
    /**
     * Provides operations to manage the collection of place entities.
     * @param string $placeId The unique identifier of place
     * @return PlaceItemRequestBuilder
    */
    public function byPlaceId(string $placeId): PlaceItemRequestBuilder {
        $urlTplParams = $this->pathParameters;
        $urlTplParams['place%2Did'] = $placeId;
        return new PlaceItemRequestBuilder($urlTplParams, $this->requestAdapter);
    }

    /**
     * Instantiates a new PlacesRequestBuilder and sets the default values.
     * @param array<string, mixed>|string $pathParametersOrRawUrl Path parameters for the request or a String representing the raw URL.
     * @param RequestAdapter $requestAdapter The request adapter to use to execute the requests.
    */
    public function __construct($pathParametersOrRawUrl, RequestAdapter $requestAdapter) {
        parent::__construct($requestAdapter, [], '{+baseurl}/places');
        if (is_array($pathParametersOrRawUrl)) {
            $this->pathParameters = $pathParametersOrRawUrl;
        } else {
            $this->pathParameters = ['request-raw-url' => $pathParametersOrRawUrl];
        }
    }

    /**
     * Create a new place object. You can also use this method to create the following child object types: building, floor, section, room, workspace, or desk.
     * @param Place $body The request body
     * @param PlacesRequestBuilderPostRequestConfiguration|null $requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
     * @return Promise<Place|null>
     * @throws Exception
     * @link https://learn.microsoft.com/graph/api/place-post?view=graph-rest-1.0 Find more info here
    */
    public function post(Place $body, ?PlacesRequestBuilderPostRequestConfiguration $requestConfiguration = null): Promise {
        $requestInfo = $this->toPostRequestInformation($body, $requestConfiguration);
        $errorMappings = [
                'XXX' => [ODataError::class, 'createFromDiscriminatorValue'],
        ];
        return $this->requestAdapter->sendAsync($requestInfo, [Place::class, 'createFromDiscriminatorValue'], $errorMappings);
    }

    /**
     * Create a new place object. You can also use this method to create the following child object types: building, floor, section, room, workspace, or desk.
     * @param Place $body The request body
     * @param PlacesRequestBuilderPostRequestConfiguration|null $requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
     * @return RequestInformation
    */
    public function toPostRequestInformation(Place $body, ?PlacesRequestBuilderPostRequestConfiguration $requestConfiguration = null): RequestInformation {
        $requestInfo = new RequestInformation();
        $requestInfo->urlTemplate = $this->urlTemplate;
        $requestInfo->pathParameters = $this->pathParameters;
        $requestInfo->httpMethod = HttpMethod::POST;
        if ($requestConfiguration !== null) {
            $requestInfo->addHeaders($requestConfiguration->headers);
            $requestInfo->addRequestOptions(...$requestConfiguration->options);
        }
        $requestInfo->tryAddHeader('Accept', "application/json");
        $requestInfo->setContentFromParsable($this->requestAdapter, "application/json", $body);
        return $requestInfo;
    }

    /**
     * Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored.
     * @param string $rawUrl The raw URL to use for the request builder.
     * @return PlacesRequestBuilder
    */
    public function withUrl(string $rawUrl): PlacesRequestBuilder {
        return new PlacesRequestBuilder($rawUrl, $this->requestAdapter);
    }

}
