// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.appconfiguration.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.appconfiguration.fluent.models.ReplicaInner;
import com.azure.resourcemanager.appconfiguration.models.Replica;
import com.azure.resourcemanager.appconfiguration.models.ReplicaProvisioningState;

public final class ReplicaImpl implements Replica, Replica.Definition {
    private ReplicaInner innerObject;

    private final com.azure.resourcemanager.appconfiguration.AppConfigurationManager serviceManager;

    ReplicaImpl(
        ReplicaInner innerObject, com.azure.resourcemanager.appconfiguration.AppConfigurationManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = 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 SystemData systemData() {
        return this.innerModel().systemData();
    }

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

    public ReplicaProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

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

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

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

    private com.azure.resourcemanager.appconfiguration.AppConfigurationManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String configStoreName;

    private String replicaName;

    public ReplicaImpl withExistingConfigurationStore(String resourceGroupName, String configStoreName) {
        this.resourceGroupName = resourceGroupName;
        this.configStoreName = configStoreName;
        return this;
    }

    public Replica create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicas()
                .create(resourceGroupName, configStoreName, replicaName, this.innerModel(), Context.NONE);
        return this;
    }

    public Replica create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicas()
                .create(resourceGroupName, configStoreName, replicaName, this.innerModel(), context);
        return this;
    }

    ReplicaImpl(String name, com.azure.resourcemanager.appconfiguration.AppConfigurationManager serviceManager) {
        this.innerObject = new ReplicaInner();
        this.serviceManager = serviceManager;
        this.replicaName = name;
    }

    public Replica refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicas()
                .getWithResponse(resourceGroupName, configStoreName, replicaName, Context.NONE)
                .getValue();
        return this;
    }

    public Replica refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicas()
                .getWithResponse(resourceGroupName, configStoreName, replicaName, context)
                .getValue();
        return this;
    }

    public ReplicaImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

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