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

package com.azure.resourcemanager.kubernetesconfiguration.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.kubernetesconfiguration.fluent.ExtensionsClient;
import com.azure.resourcemanager.kubernetesconfiguration.fluent.models.ExtensionInner;
import com.azure.resourcemanager.kubernetesconfiguration.models.Extension;
import com.azure.resourcemanager.kubernetesconfiguration.models.Extensions;
import com.azure.resourcemanager.kubernetesconfiguration.models.PatchExtension;

public final class ExtensionsImpl implements Extensions {
    private static final ClientLogger LOGGER = new ClientLogger(ExtensionsImpl.class);

    private final ExtensionsClient innerClient;

    private final com.azure.resourcemanager.kubernetesconfiguration.SourceControlConfigurationManager serviceManager;

    public ExtensionsImpl(
        ExtensionsClient innerClient,
        com.azure.resourcemanager.kubernetesconfiguration.SourceControlConfigurationManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Extension create(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension) {
        ExtensionInner inner =
            this
                .serviceClient()
                .create(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Extension create(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension,
        Context context) {
        ExtensionInner inner =
            this
                .serviceClient()
                .create(
                    resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension, context);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Extension> getWithResponse(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Context context) {
        Response<ExtensionInner> inner =
            this
                .serviceClient()
                .getWithResponse(
                    resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ExtensionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Extension get(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        ExtensionInner inner =
            this.serviceClient().get(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void delete(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        this.serviceClient().delete(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName);
    }

    public void delete(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete,
        Context context) {
        this
            .serviceClient()
            .delete(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete, context);
    }

    public Extension update(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension) {
        ExtensionInner inner =
            this
                .serviceClient()
                .update(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Extension update(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension,
        Context context) {
        ExtensionInner inner =
            this
                .serviceClient()
                .update(
                    resourceGroupName,
                    clusterRp,
                    clusterResourceName,
                    clusterName,
                    extensionName,
                    patchExtension,
                    context);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<Extension> list(
        String resourceGroupName, String clusterRp, String clusterResourceName, String clusterName) {
        PagedIterable<ExtensionInner> inner =
            this.serviceClient().list(resourceGroupName, clusterRp, clusterResourceName, clusterName);
        return Utils.mapPage(inner, inner1 -> new ExtensionImpl(inner1, this.manager()));
    }

    public PagedIterable<Extension> list(
        String resourceGroupName, String clusterRp, String clusterResourceName, String clusterName, Context context) {
        PagedIterable<ExtensionInner> inner =
            this.serviceClient().list(resourceGroupName, clusterRp, clusterResourceName, clusterName, context);
        return Utils.mapPage(inner, inner1 -> new ExtensionImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.kubernetesconfiguration.SourceControlConfigurationManager manager() {
        return this.serviceManager;
    }
}
