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

package azure.resourcemanager.multiserviceolderversions.combined.implementation;

import azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient;
import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner;
import azure.resourcemanager.multiserviceolderversions.combined.models.Disk;
import azure.resourcemanager.multiserviceolderversions.combined.models.Disks;
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 DisksImpl implements Disks {
    private static final ClientLogger LOGGER = new ClientLogger(DisksImpl.class);

    private final DisksClient innerClient;

    private final azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager;

    public DisksImpl(DisksClient innerClient,
        azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<Disk> getByResourceGroupWithResponse(String resourceGroupName, String diskName, Context context) {
        Response<DiskInner> inner
            = this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, diskName, context);
        if (inner != null) {
            return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(),
                new DiskImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Disk getByResourceGroup(String resourceGroupName, String diskName) {
        DiskInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, diskName);
        if (inner != null) {
            return new DiskImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

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

    private azure.resourcemanager.multiserviceolderversions.combined.CombinedManager manager() {
        return this.serviceManager;
    }

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