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

package com.azure.resourcemanager.agrifood.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.agrifood.fluent.ExtensionsClient;
import com.azure.resourcemanager.agrifood.fluent.models.ExtensionInner;
import com.azure.resourcemanager.agrifood.models.Extension;
import com.azure.resourcemanager.agrifood.models.Extensions;
import java.util.List;

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

    private final ExtensionsClient innerClient;

    private final com.azure.resourcemanager.agrifood.AgriFoodManager serviceManager;

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

    public Extension create(String resourceGroupName, String farmBeatsResourceName, String extensionId) {
        ExtensionInner inner = this.serviceClient().create(resourceGroupName, farmBeatsResourceName, extensionId);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Extension> createWithResponse(
        String resourceGroupName, String farmBeatsResourceName, String extensionId, Context context) {
        Response<ExtensionInner> inner =
            this.serviceClient().createWithResponse(resourceGroupName, farmBeatsResourceName, extensionId, 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 farmBeatsResourceName, String extensionId) {
        ExtensionInner inner = this.serviceClient().get(resourceGroupName, farmBeatsResourceName, extensionId);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public Extension update(String resourceGroupName, String farmBeatsResourceName, String extensionId) {
        ExtensionInner inner = this.serviceClient().update(resourceGroupName, farmBeatsResourceName, extensionId);
        if (inner != null) {
            return new ExtensionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public void delete(String resourceGroupName, String farmBeatsResourceName, String extensionId) {
        this.serviceClient().delete(resourceGroupName, farmBeatsResourceName, extensionId);
    }

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

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

    public PagedIterable<Extension> listByFarmBeats(
        String resourceGroupName,
        String farmBeatsResourceName,
        List<String> extensionIds,
        List<String> extensionCategories,
        Integer maxPageSize,
        String skipToken,
        Context context) {
        PagedIterable<ExtensionInner> inner =
            this
                .serviceClient()
                .listByFarmBeats(
                    resourceGroupName,
                    farmBeatsResourceName,
                    extensionIds,
                    extensionCategories,
                    maxPageSize,
                    skipToken,
                    context);
        return Utils.mapPage(inner, inner1 -> new ExtensionImpl(inner1, this.manager()));
    }

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

    private com.azure.resourcemanager.agrifood.AgriFoodManager manager() {
        return this.serviceManager;
    }
}
