// 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.GeoBackupPolicyInner;
import com.azure.resourcemanager.synapse.models.GeoBackupPolicy;
import com.azure.resourcemanager.synapse.models.GeoBackupPolicyName;
import com.azure.resourcemanager.synapse.models.GeoBackupPolicyState;

public final class GeoBackupPolicyImpl implements GeoBackupPolicy, GeoBackupPolicy.Definition, GeoBackupPolicy.Update {
    private GeoBackupPolicyInner 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 GeoBackupPolicyState state() {
        return this.innerModel().state();
    }

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String workspaceName;

    private String sqlPoolName;

    private GeoBackupPolicyName geoBackupPolicyName;

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

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

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

    GeoBackupPolicyImpl(GeoBackupPolicyName name, com.azure.resourcemanager.synapse.SynapseManager serviceManager) {
        this.innerObject = new GeoBackupPolicyInner();
        this.serviceManager = serviceManager;
        this.geoBackupPolicyName = name;
    }

    public GeoBackupPolicyImpl update() {
        return this;
    }

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

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

    GeoBackupPolicyImpl(
        GeoBackupPolicyInner 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.geoBackupPolicyName =
            GeoBackupPolicyName.fromString(Utils.getValueFromIdByName(innerObject.id(), "geoBackupPolicies"));
    }

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

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

    public GeoBackupPolicyImpl withState(GeoBackupPolicyState state) {
        this.innerModel().withState(state);
        return this;
    }
}
