// 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.TransparentDataEncryptionInner;
import com.azure.resourcemanager.synapse.models.TransparentDataEncryption;
import com.azure.resourcemanager.synapse.models.TransparentDataEncryptionName;
import com.azure.resourcemanager.synapse.models.TransparentDataEncryptionStatus;

public final class TransparentDataEncryptionImpl
    implements TransparentDataEncryption, TransparentDataEncryption.Definition, TransparentDataEncryption.Update {
    private TransparentDataEncryptionInner 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 location() {
        return this.innerModel().location();
    }

    public TransparentDataEncryptionStatus status() {
        return this.innerModel().status();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private String sqlPoolName;

    private TransparentDataEncryptionName transparentDataEncryptionName;

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

    public TransparentDataEncryption create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolTransparentDataEncryptions()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    transparentDataEncryptionName,
                    this.innerModel(),
                    Context.NONE)
                .getValue();
        return this;
    }

    public TransparentDataEncryption create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolTransparentDataEncryptions()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    transparentDataEncryptionName,
                    this.innerModel(),
                    context)
                .getValue();
        return this;
    }

    TransparentDataEncryptionImpl(
        TransparentDataEncryptionName name, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new TransparentDataEncryptionInner();
        this.serviceManager = serviceManager;
        this.transparentDataEncryptionName = name;
    }

    public TransparentDataEncryptionImpl update() {
        return this;
    }

    public TransparentDataEncryption apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolTransparentDataEncryptions()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    transparentDataEncryptionName,
                    this.innerModel(),
                    Context.NONE)
                .getValue();
        return this;
    }

    public TransparentDataEncryption apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolTransparentDataEncryptions()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    workspaceName,
                    sqlPoolName,
                    transparentDataEncryptionName,
                    this.innerModel(),
                    context)
                .getValue();
        return this;
    }

    TransparentDataEncryptionImpl(
        TransparentDataEncryptionInner 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.transparentDataEncryptionName =
            TransparentDataEncryptionName
                .fromString(Utils.getValueFromIdByName(innerObject.id(), "transparentDataEncryption"));
    }

    public TransparentDataEncryption refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolTransparentDataEncryptions()
                .getWithResponse(
                    resourceGroupName, workspaceName, sqlPoolName, transparentDataEncryptionName, Context.NONE)
                .getValue();
        return this;
    }

    public TransparentDataEncryption refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSqlPoolTransparentDataEncryptions()
                .getWithResponse(resourceGroupName, workspaceName, sqlPoolName, transparentDataEncryptionName, context)
                .getValue();
        return this;
    }

    public TransparentDataEncryptionImpl withStatus(TransparentDataEncryptionStatus status) {
        this.innerModel().withStatus(status);
        return this;
    }
}
