// 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 azure.resourcemanager.methodsubscriptionid.models.SubscriptionResource2;
import azure.resourcemanager.methodsubscriptionid.models.TwoSubscriptionResourcesMethodLevelSubscriptionResource2Operations;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;

public final class TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsImpl
    implements TwoSubscriptionResourcesMethodLevelSubscriptionResource2Operations {
    private static final ClientLogger LOGGER
        = new ClientLogger(TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsImpl.class);

    private final TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsClient innerClient;

    private final azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager;

    public TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsImpl(
        TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsClient innerClient,
        azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<SubscriptionResource2> getWithResponse(String subscriptionId, String subscriptionResource2Name,
        Context context) {
        Response<SubscriptionResource2Inner> inner
            = this.serviceClient().getWithResponse(subscriptionId, subscriptionResource2Name, context);
        if (inner != null) {
            return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(),
                new SubscriptionResource2Impl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SubscriptionResource2 get(String subscriptionId, String subscriptionResource2Name) {
        SubscriptionResource2Inner inner = this.serviceClient().get(subscriptionId, subscriptionResource2Name);
        if (inner != null) {
            return new SubscriptionResource2Impl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteByResourceGroupWithResponse(String subscriptionId, String subscriptionResource2Name,
        Context context) {
        return this.serviceClient().deleteWithResponse(subscriptionId, subscriptionResource2Name, context);
    }

    public void deleteByResourceGroup(String subscriptionId, String subscriptionResource2Name) {
        this.serviceClient().delete(subscriptionId, subscriptionResource2Name);
    }

    public SubscriptionResource2 getById(String id) {
        String subscriptionId = ResourceManagerUtils.getValueFromIdByName(id, "subscriptions");
        if (subscriptionId == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(
                String.format("The resource ID '%s' is not valid. Missing path segment 'subscriptions'.", id)));
        }
        String subscriptionResource2Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource2s");
        if (subscriptionResource2Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource2s'.", id)));
        }
        return this.getWithResponse(subscriptionId, subscriptionResource2Name, Context.NONE).getValue();
    }

    public Response<SubscriptionResource2> getByIdWithResponse(String id, Context context) {
        String subscriptionId = ResourceManagerUtils.getValueFromIdByName(id, "subscriptions");
        if (subscriptionId == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(
                String.format("The resource ID '%s' is not valid. Missing path segment 'subscriptions'.", id)));
        }
        String subscriptionResource2Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource2s");
        if (subscriptionResource2Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource2s'.", id)));
        }
        return this.getWithResponse(subscriptionId, subscriptionResource2Name, context);
    }

    public void deleteById(String id) {
        String subscriptionId = ResourceManagerUtils.getValueFromIdByName(id, "subscriptions");
        if (subscriptionId == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(
                String.format("The resource ID '%s' is not valid. Missing path segment 'subscriptions'.", id)));
        }
        String subscriptionResource2Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource2s");
        if (subscriptionResource2Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource2s'.", id)));
        }
        this.deleteByResourceGroupWithResponse(subscriptionId, subscriptionResource2Name, Context.NONE);
    }

    public Response<Void> deleteByIdWithResponse(String id, Context context) {
        String subscriptionId = ResourceManagerUtils.getValueFromIdByName(id, "subscriptions");
        if (subscriptionId == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(
                String.format("The resource ID '%s' is not valid. Missing path segment 'subscriptions'.", id)));
        }
        String subscriptionResource2Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource2s");
        if (subscriptionResource2Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource2s'.", id)));
        }
        return this.deleteByResourceGroupWithResponse(subscriptionId, subscriptionResource2Name, context);
    }

    private TwoSubscriptionResourcesMethodLevelSubscriptionResource2OperationsClient serviceClient() {
        return this.innerClient;
    }

    private azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager manager() {
        return this.serviceManager;
    }

    public SubscriptionResource2Impl define(String name) {
        return new SubscriptionResource2Impl(name, this.manager());
    }
}
