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

public final class ConfigurationAssignmentsForSubscriptionsImpl implements ConfigurationAssignmentsForSubscriptions {
    private static final ClientLogger LOGGER = new ClientLogger(ConfigurationAssignmentsForSubscriptionsImpl.class);

    private final ConfigurationAssignmentsForSubscriptionsClient innerClient;

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

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

    public Response<ConfigurationAssignment> getWithResponse(String configurationAssignmentName, Context context) {
        Response<ConfigurationAssignmentInner> inner =
            this.serviceClient().getWithResponse(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 get(String configurationAssignmentName) {
        ConfigurationAssignmentInner inner = this.serviceClient().get(configurationAssignmentName);
        if (inner != null) {
            return new ConfigurationAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<ConfigurationAssignment> deleteWithResponse(String configurationAssignmentName, Context context) {
        Response<ConfigurationAssignmentInner> inner =
            this.serviceClient().deleteWithResponse(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 configurationAssignmentName) {
        ConfigurationAssignmentInner inner = this.serviceClient().delete(configurationAssignmentName);
        if (inner != null) {
            return new ConfigurationAssignmentImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public ConfigurationAssignment getById(String id) {
        String configurationAssignmentName = Utils.getValueFromIdByName(id, "configurationAssignments");
        if (configurationAssignmentName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'configurationAssignments'.",
                                id)));
        }
        return this.getWithResponse(configurationAssignmentName, Context.NONE).getValue();
    }

    public Response<ConfigurationAssignment> getByIdWithResponse(String id, Context context) {
        String configurationAssignmentName = Utils.getValueFromIdByName(id, "configurationAssignments");
        if (configurationAssignmentName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'configurationAssignments'.",
                                id)));
        }
        return this.getWithResponse(configurationAssignmentName, context);
    }

    public ConfigurationAssignment deleteById(String id) {
        String configurationAssignmentName = Utils.getValueFromIdByName(id, "configurationAssignments");
        if (configurationAssignmentName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'configurationAssignments'.",
                                id)));
        }
        return this.deleteWithResponse(configurationAssignmentName, Context.NONE).getValue();
    }

    public Response<ConfigurationAssignment> deleteByIdWithResponse(String id, Context context) {
        String configurationAssignmentName = Utils.getValueFromIdByName(id, "configurationAssignments");
        if (configurationAssignmentName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'configurationAssignments'.",
                                id)));
        }
        return this.deleteWithResponse(configurationAssignmentName, context);
    }

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

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

    public ConfigurationAssignmentImpl define(String name) {
        return new ConfigurationAssignmentImpl(name, this.manager());
    }
}
