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

package azure.resourcemanager.commonproperties.implementation;

import azure.resourcemanager.commonproperties.fluent.ArmResourceIdentifiersClient;
import azure.resourcemanager.commonproperties.fluent.models.ArmResourceIdentifierResourceInner;
import azure.resourcemanager.commonproperties.models.ArmResourceIdentifierResource;
import azure.resourcemanager.commonproperties.models.ArmResourceIdentifiers;
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 ArmResourceIdentifiersImpl implements ArmResourceIdentifiers {
    private static final ClientLogger LOGGER = new ClientLogger(ArmResourceIdentifiersImpl.class);

    private final ArmResourceIdentifiersClient innerClient;

    private final azure.resourcemanager.commonproperties.CommonPropertiesManager serviceManager;

    public ArmResourceIdentifiersImpl(ArmResourceIdentifiersClient innerClient,
        azure.resourcemanager.commonproperties.CommonPropertiesManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<ArmResourceIdentifierResource> getByResourceGroupWithResponse(String resourceGroupName,
        String armResourceIdentifierResourceName, Context context) {
        Response<ArmResourceIdentifierResourceInner> inner = this.serviceClient()
            .getByResourceGroupWithResponse(resourceGroupName, armResourceIdentifierResourceName, context);
        return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(),
            new ArmResourceIdentifierResourceImpl(inner.getValue(), this.manager()));
    }

    public ArmResourceIdentifierResource getByResourceGroup(String resourceGroupName,
        String armResourceIdentifierResourceName) {
        ArmResourceIdentifierResourceInner inner
            = this.serviceClient().getByResourceGroup(resourceGroupName, armResourceIdentifierResourceName);
        if (inner != null) {
            return new ArmResourceIdentifierResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public ArmResourceIdentifierResource getById(String id) {
        String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(
                String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String armResourceIdentifierResourceName
            = ResourceManagerUtils.getValueFromIdByName(id, "armResourceIdentifierResources");
        if (armResourceIdentifierResourceName == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String.format(
                "The resource ID '%s' is not valid. Missing path segment 'armResourceIdentifierResources'.", id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, armResourceIdentifierResourceName, Context.NONE)
            .getValue();
    }

    public Response<ArmResourceIdentifierResource> getByIdWithResponse(String id, Context context) {
        String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(
                String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String armResourceIdentifierResourceName
            = ResourceManagerUtils.getValueFromIdByName(id, "armResourceIdentifierResources");
        if (armResourceIdentifierResourceName == null) {
            throw LOGGER.logExceptionAsError(new IllegalArgumentException(String.format(
                "The resource ID '%s' is not valid. Missing path segment 'armResourceIdentifierResources'.", id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, armResourceIdentifierResourceName, context);
    }

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

    private azure.resourcemanager.commonproperties.CommonPropertiesManager manager() {
        return this.serviceManager;
    }

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