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

package com.azure.resourcemanager.automanage.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.automanage.fluent.ConfigurationProfilesVersionsClient;
import com.azure.resourcemanager.automanage.fluent.models.ConfigurationProfileInner;
import com.azure.resourcemanager.automanage.models.ConfigurationProfile;
import com.azure.resourcemanager.automanage.models.ConfigurationProfilesVersions;

public final class ConfigurationProfilesVersionsImpl implements ConfigurationProfilesVersions {
    private static final ClientLogger LOGGER = new ClientLogger(ConfigurationProfilesVersionsImpl.class);

    private final ConfigurationProfilesVersionsClient innerClient;

    private final com.azure.resourcemanager.automanage.AutomanageManager serviceManager;

    public ConfigurationProfilesVersionsImpl(
        ConfigurationProfilesVersionsClient innerClient,
        com.azure.resourcemanager.automanage.AutomanageManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public ConfigurationProfile createOrUpdate(
        String configurationProfileName,
        String versionName,
        String resourceGroupName,
        ConfigurationProfileInner parameters) {
        ConfigurationProfileInner inner =
            this.serviceClient().createOrUpdate(configurationProfileName, versionName, resourceGroupName, parameters);
        if (inner != null) {
            return new ConfigurationProfileImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ConfigurationProfile> createOrUpdateWithResponse(
        String configurationProfileName,
        String versionName,
        String resourceGroupName,
        ConfigurationProfileInner parameters,
        Context context) {
        Response<ConfigurationProfileInner> inner =
            this
                .serviceClient()
                .createOrUpdateWithResponse(
                    configurationProfileName, versionName, resourceGroupName, parameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ConfigurationProfileImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ConfigurationProfile get(String configurationProfileName, String versionName, String resourceGroupName) {
        ConfigurationProfileInner inner =
            this.serviceClient().get(configurationProfileName, versionName, resourceGroupName);
        if (inner != null) {
            return new ConfigurationProfileImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ConfigurationProfile> getWithResponse(
        String configurationProfileName, String versionName, String resourceGroupName, Context context) {
        Response<ConfigurationProfileInner> inner =
            this.serviceClient().getWithResponse(configurationProfileName, versionName, resourceGroupName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ConfigurationProfileImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public void delete(String resourceGroupName, String configurationProfileName, String versionName) {
        this.serviceClient().delete(resourceGroupName, configurationProfileName, versionName);
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName, String configurationProfileName, String versionName, Context context) {
        return this
            .serviceClient()
            .deleteWithResponse(resourceGroupName, configurationProfileName, versionName, context);
    }

    public PagedIterable<ConfigurationProfile> listChildResources(
        String configurationProfileName, String resourceGroupName) {
        PagedIterable<ConfigurationProfileInner> inner =
            this.serviceClient().listChildResources(configurationProfileName, resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new ConfigurationProfileImpl(inner1, this.manager()));
    }

    public PagedIterable<ConfigurationProfile> listChildResources(
        String configurationProfileName, String resourceGroupName, Context context) {
        PagedIterable<ConfigurationProfileInner> inner =
            this.serviceClient().listChildResources(configurationProfileName, resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new ConfigurationProfileImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.automanage.AutomanageManager manager() {
        return this.serviceManager;
    }
}
