// 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.ConfigurationAssignmentsClient;
import com.azure.resourcemanager.maintenance.fluent.models.ConfigurationAssignmentInner;
import com.azure.resourcemanager.maintenance.models.ConfigurationAssignment;
import com.azure.resourcemanager.maintenance.models.ConfigurationAssignments;

public final class ConfigurationAssignmentsImpl implements ConfigurationAssignments {
    private static final ClientLogger LOGGER = new ClientLogger(ConfigurationAssignmentsImpl.class);

    private final ConfigurationAssignmentsClient innerClient;

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

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

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

    public ConfigurationAssignment createOrUpdateParent(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName,
        String configurationAssignmentName,
        ConfigurationAssignmentInner configurationAssignment) {
        ConfigurationAssignmentInner inner =
            this
                .serviceClient()
                .createOrUpdateParent(
                    resourceGroupName,
                    providerName,
                    resourceParentType,
                    resourceParentName,
                    resourceType,
                    resourceName,
                    configurationAssignmentName,
                    configurationAssignment);
        if (inner != null) {
            return new ConfigurationAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public ConfigurationAssignment deleteParent(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName,
        String configurationAssignmentName) {
        ConfigurationAssignmentInner inner =
            this
                .serviceClient()
                .deleteParent(
                    resourceGroupName,
                    providerName,
                    resourceParentType,
                    resourceParentName,
                    resourceType,
                    resourceName,
                    configurationAssignmentName);
        if (inner != null) {
            return new ConfigurationAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    public ConfigurationAssignment createOrUpdate(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String configurationAssignmentName,
        ConfigurationAssignmentInner configurationAssignment) {
        ConfigurationAssignmentInner inner =
            this
                .serviceClient()
                .createOrUpdate(
                    resourceGroupName,
                    providerName,
                    resourceType,
                    resourceName,
                    configurationAssignmentName,
                    configurationAssignment);
        if (inner != null) {
            return new ConfigurationAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ConfigurationAssignment> deleteWithResponse(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String configurationAssignmentName,
        Context context) {
        Response<ConfigurationAssignmentInner> inner =
            this
                .serviceClient()
                .deleteWithResponse(
                    resourceGroupName, providerName, resourceType, resourceName, configurationAssignmentName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ConfigurationAssignmentImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ConfigurationAssignment delete(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String configurationAssignmentName) {
        ConfigurationAssignmentInner inner =
            this
                .serviceClient()
                .delete(resourceGroupName, providerName, resourceType, resourceName, configurationAssignmentName);
        if (inner != null) {
            return new ConfigurationAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<ConfigurationAssignment> listParent(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName) {
        PagedIterable<ConfigurationAssignmentInner> inner =
            this
                .serviceClient()
                .listParent(
                    resourceGroupName,
                    providerName,
                    resourceParentType,
                    resourceParentName,
                    resourceType,
                    resourceName);
        return Utils.mapPage(inner, inner1 -> new ConfigurationAssignmentImpl(inner1, this.manager()));
    }

    public PagedIterable<ConfigurationAssignment> listParent(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName,
        Context context) {
        PagedIterable<ConfigurationAssignmentInner> inner =
            this
                .serviceClient()
                .listParent(
                    resourceGroupName,
                    providerName,
                    resourceParentType,
                    resourceParentName,
                    resourceType,
                    resourceName,
                    context);
        return Utils.mapPage(inner, inner1 -> new ConfigurationAssignmentImpl(inner1, this.manager()));
    }

    public PagedIterable<ConfigurationAssignment> list(
        String resourceGroupName, String providerName, String resourceType, String resourceName) {
        PagedIterable<ConfigurationAssignmentInner> inner =
            this.serviceClient().list(resourceGroupName, providerName, resourceType, resourceName);
        return Utils.mapPage(inner, inner1 -> new ConfigurationAssignmentImpl(inner1, this.manager()));
    }

    public PagedIterable<ConfigurationAssignment> list(
        String resourceGroupName, String providerName, String resourceType, String resourceName, Context context) {
        PagedIterable<ConfigurationAssignmentInner> inner =
            this.serviceClient().list(resourceGroupName, providerName, resourceType, resourceName, context);
        return Utils.mapPage(inner, inner1 -> new ConfigurationAssignmentImpl(inner1, this.manager()));
    }

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

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