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

package com.azure.resourcemanager.avs.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.avs.fluent.models.GlobalReachConnectionInner;
import com.azure.resourcemanager.avs.models.GlobalReachConnection;
import com.azure.resourcemanager.avs.models.GlobalReachConnectionProvisioningState;
import com.azure.resourcemanager.avs.models.GlobalReachConnectionStatus;

public final class GlobalReachConnectionImpl
    implements GlobalReachConnection, GlobalReachConnection.Definition, GlobalReachConnection.Update {
    private GlobalReachConnectionInner innerObject;

    private final com.azure.resourcemanager.avs.AvsManager serviceManager;

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

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

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

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

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

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

    public GlobalReachConnectionStatus circuitConnectionStatus() {
        return this.innerModel().circuitConnectionStatus();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.avs.AvsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String privateCloudName;

    private String globalReachConnectionName;

    public GlobalReachConnectionImpl withExistingPrivateCloud(String resourceGroupName, String privateCloudName) {
        this.resourceGroupName = resourceGroupName;
        this.privateCloudName = privateCloudName;
        return this;
    }

    public GlobalReachConnection create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGlobalReachConnections()
                .createOrUpdate(
                    resourceGroupName, privateCloudName, globalReachConnectionName, this.innerModel(), Context.NONE);
        return this;
    }

    public GlobalReachConnection create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGlobalReachConnections()
                .createOrUpdate(
                    resourceGroupName, privateCloudName, globalReachConnectionName, this.innerModel(), context);
        return this;
    }

    GlobalReachConnectionImpl(String name, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = new GlobalReachConnectionInner();
        this.serviceManager = serviceManager;
        this.globalReachConnectionName = name;
    }

    public GlobalReachConnectionImpl update() {
        return this;
    }

    public GlobalReachConnection apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGlobalReachConnections()
                .createOrUpdate(
                    resourceGroupName, privateCloudName, globalReachConnectionName, this.innerModel(), Context.NONE);
        return this;
    }

    public GlobalReachConnection apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGlobalReachConnections()
                .createOrUpdate(
                    resourceGroupName, privateCloudName, globalReachConnectionName, this.innerModel(), context);
        return this;
    }

    GlobalReachConnectionImpl(
        GlobalReachConnectionInner innerObject, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.privateCloudName = Utils.getValueFromIdByName(innerObject.id(), "privateClouds");
        this.globalReachConnectionName = Utils.getValueFromIdByName(innerObject.id(), "globalReachConnections");
    }

    public GlobalReachConnection refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGlobalReachConnections()
                .getWithResponse(resourceGroupName, privateCloudName, globalReachConnectionName, Context.NONE)
                .getValue();
        return this;
    }

    public GlobalReachConnection refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGlobalReachConnections()
                .getWithResponse(resourceGroupName, privateCloudName, globalReachConnectionName, context)
                .getValue();
        return this;
    }

    public GlobalReachConnectionImpl withAuthorizationKey(String authorizationKey) {
        this.innerModel().withAuthorizationKey(authorizationKey);
        return this;
    }

    public GlobalReachConnectionImpl withPeerExpressRouteCircuit(String peerExpressRouteCircuit) {
        this.innerModel().withPeerExpressRouteCircuit(peerExpressRouteCircuit);
        return this;
    }

    public GlobalReachConnectionImpl withExpressRouteId(String expressRouteId) {
        this.innerModel().withExpressRouteId(expressRouteId);
        return this;
    }
}
