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

package com.azure.resourcemanager.advisor.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.advisor.fluent.ConfigurationsClient;
import com.azure.resourcemanager.advisor.fluent.models.ConfigDataInner;
import com.azure.resourcemanager.advisor.models.ConfigData;
import com.azure.resourcemanager.advisor.models.ConfigurationName;
import com.azure.resourcemanager.advisor.models.Configurations;

public final class ConfigurationsImpl implements Configurations {
    private static final ClientLogger LOGGER = new ClientLogger(ConfigurationsImpl.class);

    private final ConfigurationsClient innerClient;

    private final com.azure.resourcemanager.advisor.AdvisorManager serviceManager;

    public ConfigurationsImpl(
        ConfigurationsClient innerClient, com.azure.resourcemanager.advisor.AdvisorManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<ConfigData> list() {
        PagedIterable<ConfigDataInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new ConfigDataImpl(inner1, this.manager()));
    }

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

    public Response<ConfigData> createInSubscriptionWithResponse(
        ConfigurationName configurationName, ConfigDataInner configContract, Context context) {
        Response<ConfigDataInner> inner =
            this.serviceClient().createInSubscriptionWithResponse(configurationName, configContract, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ConfigDataImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ConfigData createInSubscription(ConfigurationName configurationName, ConfigDataInner configContract) {
        ConfigDataInner inner = this.serviceClient().createInSubscription(configurationName, configContract);
        if (inner != null) {
            return new ConfigDataImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<ConfigData> listByResourceGroup(String resourceGroup) {
        PagedIterable<ConfigDataInner> inner = this.serviceClient().listByResourceGroup(resourceGroup);
        return Utils.mapPage(inner, inner1 -> new ConfigDataImpl(inner1, this.manager()));
    }

    public PagedIterable<ConfigData> listByResourceGroup(String resourceGroup, Context context) {
        PagedIterable<ConfigDataInner> inner = this.serviceClient().listByResourceGroup(resourceGroup, context);
        return Utils.mapPage(inner, inner1 -> new ConfigDataImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.advisor.AdvisorManager manager() {
        return this.serviceManager;
    }

    public ConfigDataImpl define(ConfigurationName name) {
        return new ConfigDataImpl(name, this.manager());
    }
}
