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

package com.azure.resourcemanager.operationsmanagement.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.operationsmanagement.fluent.SolutionsClient;
import com.azure.resourcemanager.operationsmanagement.fluent.models.SolutionInner;
import com.azure.resourcemanager.operationsmanagement.fluent.models.SolutionPropertiesListInner;
import com.azure.resourcemanager.operationsmanagement.models.Solution;
import com.azure.resourcemanager.operationsmanagement.models.SolutionPropertiesList;
import com.azure.resourcemanager.operationsmanagement.models.Solutions;

public final class SolutionsImpl implements Solutions {
    private static final ClientLogger LOGGER = new ClientLogger(SolutionsImpl.class);

    private final SolutionsClient innerClient;

    private final com.azure.resourcemanager.operationsmanagement.OperationsManagementManager serviceManager;

    public SolutionsImpl(
        SolutionsClient innerClient,
        com.azure.resourcemanager.operationsmanagement.OperationsManagementManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public void deleteByResourceGroup(String resourceGroupName, String solutionName) {
        this.serviceClient().delete(resourceGroupName, solutionName);
    }

    public void delete(String resourceGroupName, String solutionName, Context context) {
        this.serviceClient().delete(resourceGroupName, solutionName, context);
    }

    public Response<Solution> getByResourceGroupWithResponse(
        String resourceGroupName, String solutionName, Context context) {
        Response<SolutionInner> inner =
            this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, solutionName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SolutionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Solution getByResourceGroup(String resourceGroupName, String solutionName) {
        SolutionInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, solutionName);
        if (inner != null) {
            return new SolutionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SolutionPropertiesList> listByResourceGroupWithResponse(String resourceGroupName, Context context) {
        Response<SolutionPropertiesListInner> inner =
            this.serviceClient().listByResourceGroupWithResponse(resourceGroupName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SolutionPropertiesListImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SolutionPropertiesList listByResourceGroup(String resourceGroupName) {
        SolutionPropertiesListInner inner = this.serviceClient().listByResourceGroup(resourceGroupName);
        if (inner != null) {
            return new SolutionPropertiesListImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SolutionPropertiesList> listBySubscriptionWithResponse(Context context) {
        Response<SolutionPropertiesListInner> inner = this.serviceClient().listBySubscriptionWithResponse(context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SolutionPropertiesListImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SolutionPropertiesList listBySubscription() {
        SolutionPropertiesListInner inner = this.serviceClient().listBySubscription();
        if (inner != null) {
            return new SolutionPropertiesListImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

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

    public void deleteById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourcegroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourcegroups'.", id)));
        }
        String solutionName = Utils.getValueFromIdByName(id, "solutions");
        if (solutionName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'solutions'.", id)));
        }
        this.delete(resourceGroupName, solutionName, Context.NONE);
    }

    public void deleteByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourcegroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourcegroups'.", id)));
        }
        String solutionName = Utils.getValueFromIdByName(id, "solutions");
        if (solutionName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'solutions'.", id)));
        }
        this.delete(resourceGroupName, solutionName, context);
    }

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

    private com.azure.resourcemanager.operationsmanagement.OperationsManagementManager manager() {
        return this.serviceManager;
    }

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