// 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.SqlPoolVulnerabilityAssessmentInner;
import com.azure.resourcemanager.synapse.models.SqlPoolVulnerabilityAssessment;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentName;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentRecurringScansProperties;

public final class SqlPoolVulnerabilityAssessmentImpl
    implements SqlPoolVulnerabilityAssessment,
        SqlPoolVulnerabilityAssessment.Definition,
        SqlPoolVulnerabilityAssessment.Update {
    private SqlPoolVulnerabilityAssessmentInner 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 String storageContainerPath() {
        return this.innerModel().storageContainerPath();
    }

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

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

    public VulnerabilityAssessmentRecurringScansProperties recurringScans() {
        return this.innerModel().recurringScans();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public SqlPoolVulnerabilityAssessmentInner 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;

    public SqlPoolVulnerabilityAssessmentImpl withExistingSqlPool(
        String resourceGroupName, String workspaceName, String sqlPoolName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        this.sqlPoolName = sqlPoolName;
        return this;
    }

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

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

    SqlPoolVulnerabilityAssessmentImpl(
        VulnerabilityAssessmentName name, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new SqlPoolVulnerabilityAssessmentInner();
        this.serviceManager = serviceManager;
        this.vulnerabilityAssessmentName = name;
    }

    public SqlPoolVulnerabilityAssessmentImpl update() {
        return this;
    }

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

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

    SqlPoolVulnerabilityAssessmentImpl(
        SqlPoolVulnerabilityAssessmentInner 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"));
    }

    public SqlPoolVulnerabilityAssessment refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessments()
                .getWithResponse(
                    resourceGroupName, workspaceName, sqlPoolName, vulnerabilityAssessmentName, Context.NONE)
                .getValue();
        return this;
    }

    public SqlPoolVulnerabilityAssessment refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolVulnerabilityAssessments()
                .getWithResponse(resourceGroupName, workspaceName, sqlPoolName, vulnerabilityAssessmentName, context)
                .getValue();
        return this;
    }

    public SqlPoolVulnerabilityAssessmentImpl withStorageContainerPath(String storageContainerPath) {
        this.innerModel().withStorageContainerPath(storageContainerPath);
        return this;
    }

    public SqlPoolVulnerabilityAssessmentImpl withStorageContainerSasKey(String storageContainerSasKey) {
        this.innerModel().withStorageContainerSasKey(storageContainerSasKey);
        return this;
    }

    public SqlPoolVulnerabilityAssessmentImpl withStorageAccountAccessKey(String storageAccountAccessKey) {
        this.innerModel().withStorageAccountAccessKey(storageAccountAccessKey);
        return this;
    }

    public SqlPoolVulnerabilityAssessmentImpl withRecurringScans(
        VulnerabilityAssessmentRecurringScansProperties recurringScans) {
        this.innerModel().withRecurringScans(recurringScans);
        return this;
    }
}
