// 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.SqlPoolSecurityAlertPolicyInner;
import com.azure.resourcemanager.synapse.models.SecurityAlertPolicyName;
import com.azure.resourcemanager.synapse.models.SecurityAlertPolicyState;
import com.azure.resourcemanager.synapse.models.SqlPoolSecurityAlertPolicy;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;

public final class SqlPoolSecurityAlertPolicyImpl
    implements SqlPoolSecurityAlertPolicy, SqlPoolSecurityAlertPolicy.Definition, SqlPoolSecurityAlertPolicy.Update {
    private SqlPoolSecurityAlertPolicyInner 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 SecurityAlertPolicyState state() {
        return this.innerModel().state();
    }

    public List<String> disabledAlerts() {
        List<String> inner = this.innerModel().disabledAlerts();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<String> emailAddresses() {
        List<String> inner = this.innerModel().emailAddresses();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public Boolean emailAccountAdmins() {
        return this.innerModel().emailAccountAdmins();
    }

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

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

    public Integer retentionDays() {
        return this.innerModel().retentionDays();
    }

    public OffsetDateTime creationTime() {
        return this.innerModel().creationTime();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private String sqlPoolName;

    private SecurityAlertPolicyName securityAlertPolicyName;

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

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

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

    SqlPoolSecurityAlertPolicyImpl(
        SecurityAlertPolicyName name, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new SqlPoolSecurityAlertPolicyInner();
        this.serviceManager = serviceManager;
        this.securityAlertPolicyName = name;
    }

    public SqlPoolSecurityAlertPolicyImpl update() {
        return this;
    }

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

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

    SqlPoolSecurityAlertPolicyImpl(
        SqlPoolSecurityAlertPolicyInner 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.securityAlertPolicyName =
            SecurityAlertPolicyName.fromString(Utils.getValueFromIdByName(innerObject.id(), "securityAlertPolicies"));
    }

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

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

    public SqlPoolSecurityAlertPolicyImpl withState(SecurityAlertPolicyState state) {
        this.innerModel().withState(state);
        return this;
    }

    public SqlPoolSecurityAlertPolicyImpl withDisabledAlerts(List<String> disabledAlerts) {
        this.innerModel().withDisabledAlerts(disabledAlerts);
        return this;
    }

    public SqlPoolSecurityAlertPolicyImpl withEmailAddresses(List<String> emailAddresses) {
        this.innerModel().withEmailAddresses(emailAddresses);
        return this;
    }

    public SqlPoolSecurityAlertPolicyImpl withEmailAccountAdmins(Boolean emailAccountAdmins) {
        this.innerModel().withEmailAccountAdmins(emailAccountAdmins);
        return this;
    }

    public SqlPoolSecurityAlertPolicyImpl withStorageEndpoint(String storageEndpoint) {
        this.innerModel().withStorageEndpoint(storageEndpoint);
        return this;
    }

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

    public SqlPoolSecurityAlertPolicyImpl withRetentionDays(Integer retentionDays) {
        this.innerModel().withRetentionDays(retentionDays);
        return this;
    }
}
