// 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.util.Context;
import com.azure.resourcemanager.synapse.fluent.models.SqlPoolVulnerabilityAssessmentRuleBaselineInner;
import com.azure.resourcemanager.synapse.models.SqlPoolVulnerabilityAssessmentRuleBaseline;
import com.azure.resourcemanager.synapse.models.SqlPoolVulnerabilityAssessmentRuleBaselineItem;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentName;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentPolicyBaselineName;
import java.util.Collections;
import java.util.List;

public final class SqlPoolVulnerabilityAssessmentRuleBaselineImpl
    implements SqlPoolVulnerabilityAssessmentRuleBaseline,
        SqlPoolVulnerabilityAssessmentRuleBaseline.Definition,
        SqlPoolVulnerabilityAssessmentRuleBaseline.Update {
    private SqlPoolVulnerabilityAssessmentRuleBaselineInner innerObject;

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

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public List<SqlPoolVulnerabilityAssessmentRuleBaselineItem> baselineResults() {
        List<SqlPoolVulnerabilityAssessmentRuleBaselineItem> inner = this.innerModel().baselineResults();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaselineInner innerModel() {
        return this.innerObject;
    }

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

    private String resourceGroupName;

    private String workspaceName;

    private String sqlPoolName;

    private VulnerabilityAssessmentName vulnerabilityAssessmentName;

    private String ruleId;

    private VulnerabilityAssessmentPolicyBaselineName baselineName;

    public SqlPoolVulnerabilityAssessmentRuleBaselineImpl withExistingRule(
        String resourceGroupName,
        String workspaceName,
        String sqlPoolName,
        VulnerabilityAssessmentName vulnerabilityAssessmentName,
        String ruleId) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        this.sqlPoolName = sqlPoolName;
        this.vulnerabilityAssessmentName = vulnerabilityAssessmentName;
        this.ruleId = ruleId;
        return this;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessmentRuleBaselines()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    vulnerabilityAssessmentName,
                    ruleId,
                    baselineName,
                    this.innerModel(),
                    Context.NONE)
                .getValue();
        return this;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessmentRuleBaselines()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    vulnerabilityAssessmentName,
                    ruleId,
                    baselineName,
                    this.innerModel(),
                    context)
                .getValue();
        return this;
    }

    SqlPoolVulnerabilityAssessmentRuleBaselineImpl(
        VulnerabilityAssessmentPolicyBaselineName name,
        com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new SqlPoolVulnerabilityAssessmentRuleBaselineInner();
        this.serviceManager = serviceManager;
        this.baselineName = name;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaselineImpl update() {
        return this;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessmentRuleBaselines()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    vulnerabilityAssessmentName,
                    ruleId,
                    baselineName,
                    this.innerModel(),
                    Context.NONE)
                .getValue();
        return this;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessmentRuleBaselines()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    vulnerabilityAssessmentName,
                    ruleId,
                    baselineName,
                    this.innerModel(),
                    context)
                .getValue();
        return this;
    }

    SqlPoolVulnerabilityAssessmentRuleBaselineImpl(
        SqlPoolVulnerabilityAssessmentRuleBaselineInner innerObject,
        com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.workspaceName = Utils.getValueFromIdByName(innerObject.id(), "workspaces");
        this.sqlPoolName = Utils.getValueFromIdByName(innerObject.id(), "sqlPools");
        this.vulnerabilityAssessmentName =
            VulnerabilityAssessmentName
                .fromString(Utils.getValueFromIdByName(innerObject.id(), "vulnerabilityAssessments"));
        this.ruleId = Utils.getValueFromIdByName(innerObject.id(), "rules");
        this.baselineName =
            VulnerabilityAssessmentPolicyBaselineName
                .fromString(Utils.getValueFromIdByName(innerObject.id(), "baselines"));
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessmentRuleBaselines()
                .getWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    vulnerabilityAssessmentName,
                    ruleId,
                    baselineName,
                    Context.NONE)
                .getValue();
        return this;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaseline refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessmentRuleBaselines()
                .getWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    vulnerabilityAssessmentName,
                    ruleId,
                    baselineName,
                    context)
                .getValue();
        return this;
    }

    public SqlPoolVulnerabilityAssessmentRuleBaselineImpl withBaselineResults(
        List<SqlPoolVulnerabilityAssessmentRuleBaselineItem> baselineResults) {
        this.innerModel().withBaselineResults(baselineResults);
        return this;
    }
}
