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

package com.azure.resourcemanager.securityinsights.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.securityinsights.fluent.SentinelOnboardingStatesClient;
import com.azure.resourcemanager.securityinsights.fluent.models.SentinelOnboardingStateInner;
import com.azure.resourcemanager.securityinsights.fluent.models.SentinelOnboardingStatesListInner;
import com.azure.resourcemanager.securityinsights.models.SentinelOnboardingState;
import com.azure.resourcemanager.securityinsights.models.SentinelOnboardingStates;
import com.azure.resourcemanager.securityinsights.models.SentinelOnboardingStatesList;

public final class SentinelOnboardingStatesImpl implements SentinelOnboardingStates {
    private static final ClientLogger LOGGER = new ClientLogger(SentinelOnboardingStatesImpl.class);

    private final SentinelOnboardingStatesClient innerClient;

    private final com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager;

    public SentinelOnboardingStatesImpl(
        SentinelOnboardingStatesClient innerClient,
        com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public SentinelOnboardingState get(
        String resourceGroupName, String workspaceName, String sentinelOnboardingStateName) {
        SentinelOnboardingStateInner inner =
            this.serviceClient().get(resourceGroupName, workspaceName, sentinelOnboardingStateName);
        if (inner != null) {
            return new SentinelOnboardingStateImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SentinelOnboardingState> getWithResponse(
        String resourceGroupName, String workspaceName, String sentinelOnboardingStateName, Context context) {
        Response<SentinelOnboardingStateInner> inner =
            this
                .serviceClient()
                .getWithResponse(resourceGroupName, workspaceName, sentinelOnboardingStateName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SentinelOnboardingStateImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public void delete(String resourceGroupName, String workspaceName, String sentinelOnboardingStateName) {
        this.serviceClient().delete(resourceGroupName, workspaceName, sentinelOnboardingStateName);
    }

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

    public SentinelOnboardingStatesList list(String resourceGroupName, String workspaceName) {
        SentinelOnboardingStatesListInner inner = this.serviceClient().list(resourceGroupName, workspaceName);
        if (inner != null) {
            return new SentinelOnboardingStatesListImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<SentinelOnboardingStatesList> listWithResponse(
        String resourceGroupName, String workspaceName, Context context) {
        Response<SentinelOnboardingStatesListInner> inner =
            this.serviceClient().listWithResponse(resourceGroupName, workspaceName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SentinelOnboardingStatesListImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SentinelOnboardingState 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 workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String sentinelOnboardingStateName = Utils.getValueFromIdByName(id, "onboardingStates");
        if (sentinelOnboardingStateName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'onboardingStates'.", id)));
        }
        return this
            .getWithResponse(resourceGroupName, workspaceName, sentinelOnboardingStateName, Context.NONE)
            .getValue();
    }

    public Response<SentinelOnboardingState> 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 workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String sentinelOnboardingStateName = Utils.getValueFromIdByName(id, "onboardingStates");
        if (sentinelOnboardingStateName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'onboardingStates'.", id)));
        }
        return this.getWithResponse(resourceGroupName, workspaceName, sentinelOnboardingStateName, 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 workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String sentinelOnboardingStateName = Utils.getValueFromIdByName(id, "onboardingStates");
        if (sentinelOnboardingStateName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'onboardingStates'.", id)));
        }
        this.deleteWithResponse(resourceGroupName, workspaceName, sentinelOnboardingStateName, Context.NONE);
    }

    public Response<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 workspaceName = Utils.getValueFromIdByName(id, "workspaces");
        if (workspaceName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'workspaces'.", id)));
        }
        String sentinelOnboardingStateName = Utils.getValueFromIdByName(id, "onboardingStates");
        if (sentinelOnboardingStateName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'onboardingStates'.", id)));
        }
        return this.deleteWithResponse(resourceGroupName, workspaceName, sentinelOnboardingStateName, context);
    }

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

    private com.azure.resourcemanager.securityinsights.SecurityInsightsManager manager() {
        return this.serviceManager;
    }

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