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

package com.azure.resourcemanager.powerbidedicated.implementation;

import com.azure.core.http.rest.PagedIterable;
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;
import com.azure.resourcemanager.powerbidedicated.fluent.CapacitiesClient;
import com.azure.resourcemanager.powerbidedicated.fluent.models.CheckCapacityNameAvailabilityResultInner;
import com.azure.resourcemanager.powerbidedicated.fluent.models.DedicatedCapacityInner;
import com.azure.resourcemanager.powerbidedicated.fluent.models.SkuEnumerationForExistingResourceResultInner;
import com.azure.resourcemanager.powerbidedicated.fluent.models.SkuEnumerationForNewResourceResultInner;
import com.azure.resourcemanager.powerbidedicated.models.Capacities;
import com.azure.resourcemanager.powerbidedicated.models.CheckCapacityNameAvailabilityParameters;
import com.azure.resourcemanager.powerbidedicated.models.CheckCapacityNameAvailabilityResult;
import com.azure.resourcemanager.powerbidedicated.models.DedicatedCapacity;
import com.azure.resourcemanager.powerbidedicated.models.SkuEnumerationForExistingResourceResult;
import com.azure.resourcemanager.powerbidedicated.models.SkuEnumerationForNewResourceResult;

public final class CapacitiesImpl implements Capacities {
    private static final ClientLogger LOGGER = new ClientLogger(CapacitiesImpl.class);

    private final CapacitiesClient innerClient;

    private final com.azure.resourcemanager.powerbidedicated.PowerBIDedicatedManager serviceManager;

    public CapacitiesImpl(
        CapacitiesClient innerClient,
        com.azure.resourcemanager.powerbidedicated.PowerBIDedicatedManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

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

    public DedicatedCapacity getByResourceGroup(String resourceGroupName, String dedicatedCapacityName) {
        DedicatedCapacityInner inner =
            this.serviceClient().getByResourceGroup(resourceGroupName, dedicatedCapacityName);
        if (inner != null) {
            return new DedicatedCapacityImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void deleteByResourceGroup(String resourceGroupName, String dedicatedCapacityName) {
        this.serviceClient().delete(resourceGroupName, dedicatedCapacityName);
    }

    public void delete(String resourceGroupName, String dedicatedCapacityName, Context context) {
        this.serviceClient().delete(resourceGroupName, dedicatedCapacityName, context);
    }

    public void suspend(String resourceGroupName, String dedicatedCapacityName) {
        this.serviceClient().suspend(resourceGroupName, dedicatedCapacityName);
    }

    public void suspend(String resourceGroupName, String dedicatedCapacityName, Context context) {
        this.serviceClient().suspend(resourceGroupName, dedicatedCapacityName, context);
    }

    public void resume(String resourceGroupName, String dedicatedCapacityName) {
        this.serviceClient().resume(resourceGroupName, dedicatedCapacityName);
    }

    public void resume(String resourceGroupName, String dedicatedCapacityName, Context context) {
        this.serviceClient().resume(resourceGroupName, dedicatedCapacityName, context);
    }

    public PagedIterable<DedicatedCapacity> listByResourceGroup(String resourceGroupName) {
        PagedIterable<DedicatedCapacityInner> inner = this.serviceClient().listByResourceGroup(resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new DedicatedCapacityImpl(inner1, this.manager()));
    }

    public PagedIterable<DedicatedCapacity> listByResourceGroup(String resourceGroupName, Context context) {
        PagedIterable<DedicatedCapacityInner> inner =
            this.serviceClient().listByResourceGroup(resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new DedicatedCapacityImpl(inner1, this.manager()));
    }

    public PagedIterable<DedicatedCapacity> list() {
        PagedIterable<DedicatedCapacityInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new DedicatedCapacityImpl(inner1, this.manager()));
    }

    public PagedIterable<DedicatedCapacity> list(Context context) {
        PagedIterable<DedicatedCapacityInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new DedicatedCapacityImpl(inner1, this.manager()));
    }

    public Response<SkuEnumerationForNewResourceResult> listSkusWithResponse(Context context) {
        Response<SkuEnumerationForNewResourceResultInner> inner = this.serviceClient().listSkusWithResponse(context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuEnumerationForNewResourceResultImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuEnumerationForNewResourceResult listSkus() {
        SkuEnumerationForNewResourceResultInner inner = this.serviceClient().listSkus();
        if (inner != null) {
            return new SkuEnumerationForNewResourceResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SkuEnumerationForExistingResourceResult> listSkusForCapacityWithResponse(
        String resourceGroupName, String dedicatedCapacityName, Context context) {
        Response<SkuEnumerationForExistingResourceResultInner> inner =
            this.serviceClient().listSkusForCapacityWithResponse(resourceGroupName, dedicatedCapacityName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SkuEnumerationForExistingResourceResultImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SkuEnumerationForExistingResourceResult listSkusForCapacity(
        String resourceGroupName, String dedicatedCapacityName) {
        SkuEnumerationForExistingResourceResultInner inner =
            this.serviceClient().listSkusForCapacity(resourceGroupName, dedicatedCapacityName);
        if (inner != null) {
            return new SkuEnumerationForExistingResourceResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<CheckCapacityNameAvailabilityResult> checkNameAvailabilityWithResponse(
        String location, CheckCapacityNameAvailabilityParameters capacityParameters, Context context) {
        Response<CheckCapacityNameAvailabilityResultInner> inner =
            this.serviceClient().checkNameAvailabilityWithResponse(location, capacityParameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CheckCapacityNameAvailabilityResultImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CheckCapacityNameAvailabilityResult checkNameAvailability(
        String location, CheckCapacityNameAvailabilityParameters capacityParameters) {
        CheckCapacityNameAvailabilityResultInner inner =
            this.serviceClient().checkNameAvailability(location, capacityParameters);
        if (inner != null) {
            return new CheckCapacityNameAvailabilityResultImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

    public void deleteById(String id) {
        String resourceGroupName = Utils.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 dedicatedCapacityName = Utils.getValueFromIdByName(id, "capacities");
        if (dedicatedCapacityName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'capacities'.", id)));
        }
        this.delete(resourceGroupName, dedicatedCapacityName, Context.NONE);
    }

    public void deleteByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.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 dedicatedCapacityName = Utils.getValueFromIdByName(id, "capacities");
        if (dedicatedCapacityName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'capacities'.", id)));
        }
        this.delete(resourceGroupName, dedicatedCapacityName, context);
    }

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

    private com.azure.resourcemanager.powerbidedicated.PowerBIDedicatedManager manager() {
        return this.serviceManager;
    }

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