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

package azure.resourcemanager.methodsubscriptionid.implementation;

import azure.resourcemanager.methodsubscriptionid.fluent.TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsClient;
import azure.resourcemanager.methodsubscriptionid.fluent.models.SubscriptionResource2Inner;
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.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.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 reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for
     * MethodSubscriptionIdClientTwoSubscriptionResourcesMethodLevelSubscriptionResource2Operations to be used by the
     * proxy service to perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(
        name = "MethodSubscriptionIdClientTwoSubscriptionResourcesMethodLevelSubscriptionResource2Operations")
    public interface TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsService {
        @Headers({ "Content-Type: application/json" })
        @Get("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/{subscriptionResource2Name}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SubscriptionResource2Inner>> get(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("subscriptionResource2Name") String subscriptionResource2Name,
            @HeaderParam("Accept") String accept, Context context);

        @Headers({ "Content-Type: application/json" })
        @Get("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/{subscriptionResource2Name}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<SubscriptionResource2Inner> getSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("subscriptionResource2Name") String subscriptionResource2Name,
            @HeaderParam("Accept") String accept, Context context);

        @Put("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/{subscriptionResource2Name}")
        @ExpectedResponses({ 200, 201 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SubscriptionResource2Inner>> put(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("subscriptionResource2Name") String subscriptionResource2Name,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") SubscriptionResource2Inner resource, Context context);

        @Put("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/{subscriptionResource2Name}")
        @ExpectedResponses({ 200, 201 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<SubscriptionResource2Inner> putSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("subscriptionResource2Name") String subscriptionResource2Name,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") SubscriptionResource2Inner resource, Context context);

        @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" })
        @Delete("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/{subscriptionResource2Name}")
        @ExpectedResponses({ 200, 204 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("subscriptionResource2Name") String subscriptionResource2Name, Context context);

        @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" })
        @Delete("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/{subscriptionResource2Name}")
        @ExpectedResponses({ 200, 204 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<Void> deleteSync(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("subscriptionResource2Name") String subscriptionResource2Name, Context context);
    }

    /**
     * Get a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 SubscriptionResource2 along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SubscriptionResource2Inner>> getWithResponseAsync(String subscriptionId,
        String subscriptionResource2Name) {
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.get(this.client.getEndpoint(), this.client.getApiVersion(), subscriptionId,
                subscriptionResource2Name, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 SubscriptionResource2 on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SubscriptionResource2Inner> getAsync(String subscriptionId, String subscriptionResource2Name) {
        return getWithResponseAsync(subscriptionId, subscriptionResource2Name)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 SubscriptionResource2 along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SubscriptionResource2Inner> getWithResponse(String subscriptionId, String subscriptionResource2Name,
        Context context) {
        final String accept = "application/json";
        return service.getSync(this.client.getEndpoint(), this.client.getApiVersion(), subscriptionId,
            subscriptionResource2Name, accept, context);
    }

    /**
     * Get a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 SubscriptionResource2.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SubscriptionResource2Inner get(String subscriptionId, String subscriptionResource2Name) {
        return getWithResponse(subscriptionId, subscriptionResource2Name, Context.NONE).getValue();
    }

    /**
     * Create a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @param resource Resource create parameters.
     * @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 concrete proxy resource types can be created by aliasing this type using a specific property type along
     * with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SubscriptionResource2Inner>> putWithResponseAsync(String subscriptionId,
        String subscriptionResource2Name, SubscriptionResource2Inner resource) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.put(this.client.getEndpoint(), this.client.getApiVersion(), subscriptionId,
                subscriptionResource2Name, contentType, accept, resource, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @param resource Resource create parameters.
     * @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 concrete proxy resource types can be created by aliasing this type using a specific property type on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SubscriptionResource2Inner> putAsync(String subscriptionId, String subscriptionResource2Name,
        SubscriptionResource2Inner resource) {
        return putWithResponseAsync(subscriptionId, subscriptionResource2Name, resource)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Create a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @param resource Resource create parameters.
     * @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 concrete proxy resource types can be created by aliasing this type using a specific property type along
     * with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SubscriptionResource2Inner> putWithResponse(String subscriptionId, String subscriptionResource2Name,
        SubscriptionResource2Inner resource, Context context) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return service.putSync(this.client.getEndpoint(), this.client.getApiVersion(), subscriptionId,
            subscriptionResource2Name, contentType, accept, resource, context);
    }

    /**
     * Create a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @param resource Resource create parameters.
     * @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 concrete proxy resource types can be created by aliasing this type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SubscriptionResource2Inner put(String subscriptionId, String subscriptionResource2Name,
        SubscriptionResource2Inner resource) {
        return putWithResponse(subscriptionId, subscriptionResource2Name, resource, Context.NONE).getValue();
    }

    /**
     * Delete a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 subscriptionId, String subscriptionResource2Name) {
        return FluxUtil
            .withContext(context -> service.delete(this.client.getEndpoint(), this.client.getApiVersion(),
                subscriptionId, subscriptionResource2Name, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 subscriptionId, String subscriptionResource2Name) {
        return deleteWithResponseAsync(subscriptionId, subscriptionResource2Name).flatMap(ignored -> Mono.empty());
    }

    /**
     * Delete a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 subscriptionId, String subscriptionResource2Name, Context context) {
        return service.deleteSync(this.client.getEndpoint(), this.client.getApiVersion(), subscriptionId,
            subscriptionResource2Name, context);
    }

    /**
     * Delete a SubscriptionResource2.
     * 
     * @param subscriptionId The ID of the target subscription. The value must be an UUID.
     * @param subscriptionResource2Name The name of the SubscriptionResource2.
     * @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 subscriptionId, String subscriptionResource2Name) {
        deleteWithResponse(subscriptionId, subscriptionResource2Name, Context.NONE);
    }
}
