// 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.TwoSubscriptionResourcesMethodLevelSubscriptionResource1OperationsClient;
import azure.resourcemanager.methodsubscriptionid.fluent.models.SubscriptionResource1Inner;
import azure.resourcemanager.methodsubscriptionid.models.SubscriptionResource1;
import azure.resourcemanager.methodsubscriptionid.models.TwoSubscriptionResourcesMethodLevelSubscriptionResource1Operations;
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 TwoSubscriptionResourcesMethodLevelSubscriptionResource1OperationsImpl
    implements TwoSubscriptionResourcesMethodLevelSubscriptionResource1Operations {
    private static final ClientLogger LOGGER
        = new ClientLogger(TwoSubscriptionResourcesMethodLevelSubscriptionResource1OperationsImpl.class);

    private final TwoSubscriptionResourcesMethodLevelSubscriptionResource1OperationsClient innerClient;

    private final azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager;

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

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

    public SubscriptionResource1 get(String subscriptionId, String subscriptionResource1Name) {
        SubscriptionResource1Inner inner = this.serviceClient().get(subscriptionId, subscriptionResource1Name);
        if (inner != null) {
            return new SubscriptionResource1Impl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

    public SubscriptionResource1 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 subscriptionResource1Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource1s");
        if (subscriptionResource1Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource1s'.", id)));
        }
        return this.getWithResponse(subscriptionId, subscriptionResource1Name, Context.NONE).getValue();
    }

    public Response<SubscriptionResource1> 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 subscriptionResource1Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource1s");
        if (subscriptionResource1Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource1s'.", id)));
        }
        return this.getWithResponse(subscriptionId, subscriptionResource1Name, 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 subscriptionResource1Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource1s");
        if (subscriptionResource1Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource1s'.", id)));
        }
        this.deleteByResourceGroupWithResponse(subscriptionId, subscriptionResource1Name, 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 subscriptionResource1Name = ResourceManagerUtils.getValueFromIdByName(id, "subscriptionResource1s");
        if (subscriptionResource1Name == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String
                .format("The resource ID '%s' is not valid. Missing path segment 'subscriptionResource1s'.", id)));
        }
        return this.deleteByResourceGroupWithResponse(subscriptionId, subscriptionResource1Name, context);
    }

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

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

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