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

package com.azure.resourcemanager.maintenance.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.maintenance.fluent.ApplyUpdatesClient;
import com.azure.resourcemanager.maintenance.fluent.models.ApplyUpdateInner;
import com.azure.resourcemanager.maintenance.models.ApplyUpdate;
import com.azure.resourcemanager.maintenance.models.ApplyUpdates;

public final class ApplyUpdatesImpl implements ApplyUpdates {
    private static final ClientLogger LOGGER = new ClientLogger(ApplyUpdatesImpl.class);

    private final ApplyUpdatesClient innerClient;

    private final com.azure.resourcemanager.maintenance.MaintenanceManager serviceManager;

    public ApplyUpdatesImpl(
        ApplyUpdatesClient innerClient, com.azure.resourcemanager.maintenance.MaintenanceManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<ApplyUpdate> getParentWithResponse(
        String resourceGroupName,
        String resourceParentType,
        String resourceParentName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName,
        Context context) {
        Response<ApplyUpdateInner> inner =
            this
                .serviceClient()
                .getParentWithResponse(
                    resourceGroupName,
                    resourceParentType,
                    resourceParentName,
                    providerName,
                    resourceType,
                    resourceName,
                    applyUpdateName,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ApplyUpdateImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ApplyUpdate getParent(
        String resourceGroupName,
        String resourceParentType,
        String resourceParentName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        ApplyUpdateInner inner =
            this
                .serviceClient()
                .getParent(
                    resourceGroupName,
                    resourceParentType,
                    resourceParentName,
                    providerName,
                    resourceType,
                    resourceName,
                    applyUpdateName);
        if (inner != null) {
            return new ApplyUpdateImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ApplyUpdate> getWithResponse(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName,
        Context context) {
        Response<ApplyUpdateInner> inner =
            this
                .serviceClient()
                .getWithResponse(resourceGroupName, providerName, resourceType, resourceName, applyUpdateName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ApplyUpdateImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ApplyUpdate get(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        ApplyUpdateInner inner =
            this.serviceClient().get(resourceGroupName, providerName, resourceType, resourceName, applyUpdateName);
        if (inner != null) {
            return new ApplyUpdateImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ApplyUpdate> createOrUpdateParentWithResponse(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName,
        Context context) {
        Response<ApplyUpdateInner> inner =
            this
                .serviceClient()
                .createOrUpdateParentWithResponse(
                    resourceGroupName,
                    providerName,
                    resourceParentType,
                    resourceParentName,
                    resourceType,
                    resourceName,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ApplyUpdateImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ApplyUpdate createOrUpdateParent(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName) {
        ApplyUpdateInner inner =
            this
                .serviceClient()
                .createOrUpdateParent(
                    resourceGroupName,
                    providerName,
                    resourceParentType,
                    resourceParentName,
                    resourceType,
                    resourceName);
        if (inner != null) {
            return new ApplyUpdateImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ApplyUpdate> createOrUpdateWithResponse(
        String resourceGroupName, String providerName, String resourceType, String resourceName, Context context) {
        Response<ApplyUpdateInner> inner =
            this
                .serviceClient()
                .createOrUpdateWithResponse(resourceGroupName, providerName, resourceType, resourceName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ApplyUpdateImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ApplyUpdate createOrUpdate(
        String resourceGroupName, String providerName, String resourceType, String resourceName) {
        ApplyUpdateInner inner =
            this.serviceClient().createOrUpdate(resourceGroupName, providerName, resourceType, resourceName);
        if (inner != null) {
            return new ApplyUpdateImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<ApplyUpdate> list() {
        PagedIterable<ApplyUpdateInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new ApplyUpdateImpl(inner1, this.manager()));
    }

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

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

    private com.azure.resourcemanager.maintenance.MaintenanceManager manager() {
        return this.serviceManager;
    }
}
