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

package com.azure.resourcemanager.synapse.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.synapse.fluent.SqlPoolVulnerabilityAssessmentRuleBaselinesClient;
import com.azure.resourcemanager.synapse.fluent.models.SqlPoolVulnerabilityAssessmentRuleBaselineInner;
import com.azure.resourcemanager.synapse.models.SqlPoolVulnerabilityAssessmentRuleBaseline;
import com.azure.resourcemanager.synapse.models.SqlPoolVulnerabilityAssessmentRuleBaselines;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentName;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentPolicyBaselineName;

public final class SqlPoolVulnerabilityAssessmentRuleBaselinesImpl
    implements SqlPoolVulnerabilityAssessmentRuleBaselines {
    private static final ClientLogger LOGGER = new ClientLogger(SqlPoolVulnerabilityAssessmentRuleBaselinesImpl.class);

    private final SqlPoolVulnerabilityAssessmentRuleBaselinesClient innerClient;

    private final com.azure.resourcemanager.synapse.SynapseManager serviceManager;

    public SqlPoolVulnerabilityAssessmentRuleBaselinesImpl(
        SqlPoolVulnerabilityAssessmentRuleBaselinesClient innerClient,
        com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName,
        String workspaceName,
        String sqlPoolName,
        VulnerabilityAssessmentName vulnerabilityAssessmentName,
        String ruleId,
        VulnerabilityAssessmentPolicyBaselineName baselineName,
        Context context) {
        return this
            .serviceClient()
            .deleteWithResponse(
                resourceGroupName,
                workspaceName,
                sqlPoolName,
                vulnerabilityAssessmentName,
                ruleId,
                baselineName,
                context);
    }

    public void delete(
        String resourceGroupName,
        String workspaceName,
        String sqlPoolName,
        VulnerabilityAssessmentName vulnerabilityAssessmentName,
        String ruleId,
        VulnerabilityAssessmentPolicyBaselineName baselineName) {
        this
            .serviceClient()
            .delete(resourceGroupName, workspaceName, sqlPoolName, vulnerabilityAssessmentName, ruleId, baselineName);
    }

    public Response<SqlPoolVulnerabilityAssessmentRuleBaseline> getWithResponse(
        String resourceGroupName,
        String workspaceName,
        String sqlPoolName,
        VulnerabilityAssessmentName vulnerabilityAssessmentName,
        String ruleId,
        VulnerabilityAssessmentPolicyBaselineName baselineName,
        Context context) {
        Response<SqlPoolVulnerabilityAssessmentRuleBaselineInner> inner =
            this
                .serviceClient()
                .getWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    vulnerabilityAssessmentName,
                    ruleId,
                    baselineName,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new SqlPoolVulnerabilityAssessmentRuleBaselineImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline get(
        String resourceGroupName,
        String workspaceName,
        String sqlPoolName,
        VulnerabilityAssessmentName vulnerabilityAssessmentName,
        String ruleId,
        VulnerabilityAssessmentPolicyBaselineName baselineName) {
        SqlPoolVulnerabilityAssessmentRuleBaselineInner inner =
            this
                .serviceClient()
                .get(resourceGroupName, workspaceName, sqlPoolName, vulnerabilityAssessmentName, ruleId, baselineName);
        if (inner != null) {
            return new SqlPoolVulnerabilityAssessmentRuleBaselineImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline 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 sqlPoolName = Utils.getValueFromIdByName(id, "sqlPools");
        if (sqlPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'sqlPools'.", id)));
        }
        String vulnerabilityAssessmentNameLocal = Utils.getValueFromIdByName(id, "vulnerabilityAssessments");
        if (vulnerabilityAssessmentNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'vulnerabilityAssessments'.",
                                id)));
        }
        VulnerabilityAssessmentName vulnerabilityAssessmentName =
            VulnerabilityAssessmentName.fromString(vulnerabilityAssessmentNameLocal);
        String ruleId = Utils.getValueFromIdByName(id, "rules");
        if (ruleId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'rules'.", id)));
        }
        String baselineNameLocal = Utils.getValueFromIdByName(id, "baselines");
        if (baselineNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'baselines'.", id)));
        }
        VulnerabilityAssessmentPolicyBaselineName baselineName =
            VulnerabilityAssessmentPolicyBaselineName.fromString(baselineNameLocal);
        return this
            .getWithResponse(
                resourceGroupName,
                workspaceName,
                sqlPoolName,
                vulnerabilityAssessmentName,
                ruleId,
                baselineName,
                Context.NONE)
            .getValue();
    }

    public Response<SqlPoolVulnerabilityAssessmentRuleBaseline> 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 sqlPoolName = Utils.getValueFromIdByName(id, "sqlPools");
        if (sqlPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'sqlPools'.", id)));
        }
        String vulnerabilityAssessmentNameLocal = Utils.getValueFromIdByName(id, "vulnerabilityAssessments");
        if (vulnerabilityAssessmentNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'vulnerabilityAssessments'.",
                                id)));
        }
        VulnerabilityAssessmentName vulnerabilityAssessmentName =
            VulnerabilityAssessmentName.fromString(vulnerabilityAssessmentNameLocal);
        String ruleId = Utils.getValueFromIdByName(id, "rules");
        if (ruleId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'rules'.", id)));
        }
        String baselineNameLocal = Utils.getValueFromIdByName(id, "baselines");
        if (baselineNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'baselines'.", id)));
        }
        VulnerabilityAssessmentPolicyBaselineName baselineName =
            VulnerabilityAssessmentPolicyBaselineName.fromString(baselineNameLocal);
        return this
            .getWithResponse(
                resourceGroupName,
                workspaceName,
                sqlPoolName,
                vulnerabilityAssessmentName,
                ruleId,
                baselineName,
                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 sqlPoolName = Utils.getValueFromIdByName(id, "sqlPools");
        if (sqlPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'sqlPools'.", id)));
        }
        String vulnerabilityAssessmentNameLocal = Utils.getValueFromIdByName(id, "vulnerabilityAssessments");
        if (vulnerabilityAssessmentNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'vulnerabilityAssessments'.",
                                id)));
        }
        VulnerabilityAssessmentName vulnerabilityAssessmentName =
            VulnerabilityAssessmentName.fromString(vulnerabilityAssessmentNameLocal);
        String ruleId = Utils.getValueFromIdByName(id, "rules");
        if (ruleId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'rules'.", id)));
        }
        String baselineNameLocal = Utils.getValueFromIdByName(id, "baselines");
        if (baselineNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'baselines'.", id)));
        }
        VulnerabilityAssessmentPolicyBaselineName baselineName =
            VulnerabilityAssessmentPolicyBaselineName.fromString(baselineNameLocal);
        this
            .deleteWithResponse(
                resourceGroupName,
                workspaceName,
                sqlPoolName,
                vulnerabilityAssessmentName,
                ruleId,
                baselineName,
                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 sqlPoolName = Utils.getValueFromIdByName(id, "sqlPools");
        if (sqlPoolName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'sqlPools'.", id)));
        }
        String vulnerabilityAssessmentNameLocal = Utils.getValueFromIdByName(id, "vulnerabilityAssessments");
        if (vulnerabilityAssessmentNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'vulnerabilityAssessments'.",
                                id)));
        }
        VulnerabilityAssessmentName vulnerabilityAssessmentName =
            VulnerabilityAssessmentName.fromString(vulnerabilityAssessmentNameLocal);
        String ruleId = Utils.getValueFromIdByName(id, "rules");
        if (ruleId == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'rules'.", id)));
        }
        String baselineNameLocal = Utils.getValueFromIdByName(id, "baselines");
        if (baselineNameLocal == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'baselines'.", id)));
        }
        VulnerabilityAssessmentPolicyBaselineName baselineName =
            VulnerabilityAssessmentPolicyBaselineName.fromString(baselineNameLocal);
        return this
            .deleteWithResponse(
                resourceGroupName,
                workspaceName,
                sqlPoolName,
                vulnerabilityAssessmentName,
                ruleId,
                baselineName,
                context);
    }

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

    private com.azure.resourcemanager.synapse.SynapseManager manager() {
        return this.serviceManager;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaselineImpl define(VulnerabilityAssessmentPolicyBaselineName name) {
        return new SqlPoolVulnerabilityAssessmentRuleBaselineImpl(name, this.manager());
    }
}
