// 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.ServerVulnerabilityAssessmentInner;
import com.azure.resourcemanager.synapse.models.ServerVulnerabilityAssessment;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentName;
import com.azure.resourcemanager.synapse.models.VulnerabilityAssessmentRecurringScansPropertiesAutoGenerated;

public final class ServerVulnerabilityAssessmentImpl
    implements ServerVulnerabilityAssessment,
        ServerVulnerabilityAssessment.Definition,
        ServerVulnerabilityAssessment.Update {
    private ServerVulnerabilityAssessmentInner 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 VulnerabilityAssessmentRecurringScansPropertiesAutoGenerated recurringScans() {
        return this.innerModel().recurringScans();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private VulnerabilityAssessmentName vulnerabilityAssessmentName;

    public ServerVulnerabilityAssessmentImpl withExistingWorkspace(String resourceGroupName, String workspaceName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        return this;
    }

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

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

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

    public ServerVulnerabilityAssessmentImpl update() {
        return this;
    }

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

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

    ServerVulnerabilityAssessmentImpl(
        ServerVulnerabilityAssessmentInner 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.vulnerabilityAssessmentName =
            VulnerabilityAssessmentName
                .fromString(Utils.getValueFromIdByName(innerObject.id(), "vulnerabilityAssessments"));
    }

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

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

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

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

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

    public ServerVulnerabilityAssessmentImpl withRecurringScans(
        VulnerabilityAssessmentRecurringScansPropertiesAutoGenerated recurringScans) {
        this.innerModel().withRecurringScans(recurringScans);
        return this;
    }
}
