// 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.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.synapse.fluent.models.EncryptionProtectorInner;
import com.azure.resourcemanager.synapse.models.EncryptionProtector;
import com.azure.resourcemanager.synapse.models.EncryptionProtectorName;
import com.azure.resourcemanager.synapse.models.ServerKeyType;

public final class EncryptionProtectorImpl
    implements EncryptionProtector, EncryptionProtector.Definition, EncryptionProtector.Update {
    private EncryptionProtectorInner 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 kind() {
        return this.innerModel().kind();
    }

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

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

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

    public ServerKeyType serverKeyType() {
        return this.innerModel().serverKeyType();
    }

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

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

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private EncryptionProtectorName encryptionProtectorName;

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

    public EncryptionProtector create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkspaceManagedSqlServerEncryptionProtectors()
                .createOrUpdate(
                    resourceGroupName, workspaceName, encryptionProtectorName, this.innerModel(), Context.NONE);
        return this;
    }

    public EncryptionProtector create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkspaceManagedSqlServerEncryptionProtectors()
                .createOrUpdate(resourceGroupName, workspaceName, encryptionProtectorName, this.innerModel(), context);
        return this;
    }

    EncryptionProtectorImpl(
        EncryptionProtectorName name, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new EncryptionProtectorInner();
        this.serviceManager = serviceManager;
        this.encryptionProtectorName = name;
    }

    public EncryptionProtectorImpl update() {
        return this;
    }

    public EncryptionProtector apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkspaceManagedSqlServerEncryptionProtectors()
                .createOrUpdate(
                    resourceGroupName, workspaceName, encryptionProtectorName, this.innerModel(), Context.NONE);
        return this;
    }

    public EncryptionProtector apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkspaceManagedSqlServerEncryptionProtectors()
                .createOrUpdate(resourceGroupName, workspaceName, encryptionProtectorName, this.innerModel(), context);
        return this;
    }

    EncryptionProtectorImpl(
        EncryptionProtectorInner 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.encryptionProtectorName =
            EncryptionProtectorName.fromString(Utils.getValueFromIdByName(innerObject.id(), "encryptionProtector"));
    }

    public EncryptionProtector refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkspaceManagedSqlServerEncryptionProtectors()
                .getWithResponse(resourceGroupName, workspaceName, encryptionProtectorName, Context.NONE)
                .getValue();
        return this;
    }

    public EncryptionProtector refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkspaceManagedSqlServerEncryptionProtectors()
                .getWithResponse(resourceGroupName, workspaceName, encryptionProtectorName, context)
                .getValue();
        return this;
    }

    public void revalidate() {
        serviceManager
            .workspaceManagedSqlServerEncryptionProtectors()
            .revalidate(resourceGroupName, workspaceName, encryptionProtectorName);
    }

    public void revalidate(Context context) {
        serviceManager
            .workspaceManagedSqlServerEncryptionProtectors()
            .revalidate(resourceGroupName, workspaceName, encryptionProtectorName, context);
    }

    public EncryptionProtectorImpl withServerKeyName(String serverKeyName) {
        this.innerModel().withServerKeyName(serverKeyName);
        return this;
    }

    public EncryptionProtectorImpl withServerKeyType(ServerKeyType serverKeyType) {
        this.innerModel().withServerKeyType(serverKeyType);
        return this;
    }
}
