// 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.DataMaskingPolicyInner;
import com.azure.resourcemanager.synapse.models.DataMaskingPolicy;
import com.azure.resourcemanager.synapse.models.DataMaskingState;

public final class DataMaskingPolicyImpl
    implements DataMaskingPolicy, DataMaskingPolicy.Definition, DataMaskingPolicy.Update {
    private DataMaskingPolicyInner 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 String kind() {
        return this.innerModel().kind();
    }

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

    public DataMaskingState dataMaskingState() {
        return this.innerModel().dataMaskingState();
    }

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private String sqlPoolName;

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

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

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

    DataMaskingPolicyImpl(com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new DataMaskingPolicyInner();
        this.serviceManager = serviceManager;
    }

    public DataMaskingPolicyImpl update() {
        return this;
    }

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

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

    DataMaskingPolicyImpl(
        DataMaskingPolicyInner 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");
    }

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

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

    public DataMaskingPolicyImpl withDataMaskingState(DataMaskingState dataMaskingState) {
        this.innerModel().withDataMaskingState(dataMaskingState);
        return this;
    }

    public DataMaskingPolicyImpl withExemptPrincipals(String exemptPrincipals) {
        this.innerModel().withExemptPrincipals(exemptPrincipals);
        return this;
    }
}
