// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.devcenter.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.devcenter.fluent.ProjectEnvironmentTypesClient;
import com.azure.resourcemanager.devcenter.fluent.models.ProjectEnvironmentTypeInner;
import com.azure.resourcemanager.devcenter.models.ProjectEnvironmentTypeListResult;
import com.azure.resourcemanager.devcenter.models.ProjectEnvironmentTypeUpdate;
import reactor.core.publisher.Mono;

/** An instance of this class provides access to all the operations defined in ProjectEnvironmentTypesClient. */
public final class ProjectEnvironmentTypesClientImpl implements ProjectEnvironmentTypesClient {
    /** The proxy service used to perform REST calls. */
    private final ProjectEnvironmentTypesService service;

    /** The service client containing this operation class. */
    private final DevCenterManagementClientImpl client;

    /**
     * Initializes an instance of ProjectEnvironmentTypesClientImpl.
     *
     * @param client the instance of the service client containing this operation class.
     */
    ProjectEnvironmentTypesClientImpl(DevCenterManagementClientImpl client) {
        this.service =
            RestProxy
                .create(ProjectEnvironmentTypesService.class, client.getHttpPipeline(), client.getSerializerAdapter());
        this.client = client;
    }

    /**
     * The interface defining all the services for DevCenterManagementClientProjectEnvironmentTypes to be used by the
     * proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "DevCenterManagementC")
    public interface ProjectEnvironmentTypesService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/environmentTypes")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ProjectEnvironmentTypeListResult>> list(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("projectName") String projectName,
            @QueryParam("$top") Integer top,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/environmentTypes/{environmentTypeName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ProjectEnvironmentTypeInner>> get(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("projectName") String projectName,
            @PathParam("environmentTypeName") String environmentTypeName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/environmentTypes/{environmentTypeName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ProjectEnvironmentTypeInner>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("projectName") String projectName,
            @PathParam("environmentTypeName") String environmentTypeName,
            @BodyParam("application/json") ProjectEnvironmentTypeInner body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/environmentTypes/{environmentTypeName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ProjectEnvironmentTypeInner>> update(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("projectName") String projectName,
            @PathParam("environmentTypeName") String environmentTypeName,
            @BodyParam("application/json") ProjectEnvironmentTypeUpdate body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/environmentTypes/{environmentTypeName}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("projectName") String projectName,
            @PathParam("environmentTypeName") String environmentTypeName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ProjectEnvironmentTypeListResult>> listNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Lists environment types for a project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param top The maximum number of resources to return from the operation. Example: '$top=10'.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ProjectEnvironmentTypeInner>> listSinglePageAsync(
        String resourceGroupName, String projectName, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            projectName,
                            top,
                            accept,
                            context))
            .<PagedResponse<ProjectEnvironmentTypeInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Lists environment types for a project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param top The maximum number of resources to return from the operation. Example: '$top=10'.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ProjectEnvironmentTypeInner>> listSinglePageAsync(
        String resourceGroupName, String projectName, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                projectName,
                top,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists environment types for a project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param top The maximum number of resources to return from the operation. Example: '$top=10'.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ProjectEnvironmentTypeInner> listAsync(
        String resourceGroupName, String projectName, Integer top) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, projectName, top),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists environment types for a project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ProjectEnvironmentTypeInner> listAsync(String resourceGroupName, String projectName) {
        final Integer top = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, projectName, top),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists environment types for a project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param top The maximum number of resources to return from the operation. Example: '$top=10'.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ProjectEnvironmentTypeInner> listAsync(
        String resourceGroupName, String projectName, Integer top, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, projectName, top, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists environment types for a project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ProjectEnvironmentTypeInner> list(String resourceGroupName, String projectName) {
        final Integer top = null;
        return new PagedIterable<>(listAsync(resourceGroupName, projectName, top));
    }

    /**
     * Lists environment types for a project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param top The maximum number of resources to return from the operation. Example: '$top=10'.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ProjectEnvironmentTypeInner> list(
        String resourceGroupName, String projectName, Integer top, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, projectName, top, context));
    }

    /**
     * Gets a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a project environment type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ProjectEnvironmentTypeInner>> getWithResponseAsync(
        String resourceGroupName, String projectName, String environmentTypeName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            projectName,
                            environmentTypeName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a project environment type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ProjectEnvironmentTypeInner>> getWithResponseAsync(
        String resourceGroupName, String projectName, String environmentTypeName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                projectName,
                environmentTypeName,
                accept,
                context);
    }

    /**
     * Gets a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a project environment type on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ProjectEnvironmentTypeInner> getAsync(
        String resourceGroupName, String projectName, String environmentTypeName) {
        return getWithResponseAsync(resourceGroupName, projectName, environmentTypeName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a project environment type along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ProjectEnvironmentTypeInner> getWithResponse(
        String resourceGroupName, String projectName, String environmentTypeName, Context context) {
        return getWithResponseAsync(resourceGroupName, projectName, environmentTypeName, context).block();
    }

    /**
     * Gets a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a project environment type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ProjectEnvironmentTypeInner get(String resourceGroupName, String projectName, String environmentTypeName) {
        return getWithResponse(resourceGroupName, projectName, environmentTypeName, Context.NONE).getValue();
    }

    /**
     * Creates or updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Represents a Project Environment Type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ProjectEnvironmentTypeInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String projectName, String environmentTypeName, ProjectEnvironmentTypeInner body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            projectName,
                            environmentTypeName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Represents a Project Environment Type.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ProjectEnvironmentTypeInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String projectName,
        String environmentTypeName,
        ProjectEnvironmentTypeInner body,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                projectName,
                environmentTypeName,
                body,
                accept,
                context);
    }

    /**
     * Creates or updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Represents a Project Environment Type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ProjectEnvironmentTypeInner> createOrUpdateAsync(
        String resourceGroupName, String projectName, String environmentTypeName, ProjectEnvironmentTypeInner body) {
        return createOrUpdateWithResponseAsync(resourceGroupName, projectName, environmentTypeName, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Represents a Project Environment Type.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ProjectEnvironmentTypeInner> createOrUpdateWithResponse(
        String resourceGroupName,
        String projectName,
        String environmentTypeName,
        ProjectEnvironmentTypeInner body,
        Context context) {
        return createOrUpdateWithResponseAsync(resourceGroupName, projectName, environmentTypeName, body, context)
            .block();
    }

    /**
     * Creates or updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Represents a Project Environment Type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ProjectEnvironmentTypeInner createOrUpdate(
        String resourceGroupName, String projectName, String environmentTypeName, ProjectEnvironmentTypeInner body) {
        return createOrUpdateWithResponse(resourceGroupName, projectName, environmentTypeName, body, Context.NONE)
            .getValue();
    }

    /**
     * Partially updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Updatable project environment type properties.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ProjectEnvironmentTypeInner>> updateWithResponseAsync(
        String resourceGroupName, String projectName, String environmentTypeName, ProjectEnvironmentTypeUpdate body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            projectName,
                            environmentTypeName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Partially updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Updatable project environment type properties.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ProjectEnvironmentTypeInner>> updateWithResponseAsync(
        String resourceGroupName,
        String projectName,
        String environmentTypeName,
        ProjectEnvironmentTypeUpdate body,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                projectName,
                environmentTypeName,
                body,
                accept,
                context);
    }

    /**
     * Partially updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Updatable project environment type properties.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ProjectEnvironmentTypeInner> updateAsync(
        String resourceGroupName, String projectName, String environmentTypeName, ProjectEnvironmentTypeUpdate body) {
        return updateWithResponseAsync(resourceGroupName, projectName, environmentTypeName, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Partially updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Updatable project environment type properties.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ProjectEnvironmentTypeInner> updateWithResponse(
        String resourceGroupName,
        String projectName,
        String environmentTypeName,
        ProjectEnvironmentTypeUpdate body,
        Context context) {
        return updateWithResponseAsync(resourceGroupName, projectName, environmentTypeName, body, context).block();
    }

    /**
     * Partially updates a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param body Updatable project environment type properties.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return represents an environment type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ProjectEnvironmentTypeInner update(
        String resourceGroupName, String projectName, String environmentTypeName, ProjectEnvironmentTypeUpdate body) {
        return updateWithResponse(resourceGroupName, projectName, environmentTypeName, body, Context.NONE).getValue();
    }

    /**
     * Deletes a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String projectName, String environmentTypeName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            projectName,
                            environmentTypeName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String projectName, String environmentTypeName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (environmentTypeName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter environmentTypeName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                projectName,
                environmentTypeName,
                accept,
                context);
    }

    /**
     * Deletes a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String projectName, String environmentTypeName) {
        return deleteWithResponseAsync(resourceGroupName, projectName, environmentTypeName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(
        String resourceGroupName, String projectName, String environmentTypeName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, projectName, environmentTypeName, context).block();
    }

    /**
     * Deletes a project environment type.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param projectName The name of the project.
     * @param environmentTypeName The name of the environment type.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String projectName, String environmentTypeName) {
        deleteWithResponse(resourceGroupName, projectName, environmentTypeName, Context.NONE);
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ProjectEnvironmentTypeInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ProjectEnvironmentTypeInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return result of the project environment type list operation along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ProjectEnvironmentTypeInner>> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
