// 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.CloudLinkInner;
import com.azure.resourcemanager.avs.models.CloudLink;
import com.azure.resourcemanager.avs.models.CloudLinkStatus;

public final class CloudLinkImpl implements CloudLink, CloudLink.Definition, CloudLink.Update {
    private CloudLinkInner 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 CloudLinkStatus status() {
        return this.innerModel().status();
    }

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String privateCloudName;

    private String cloudLinkName;

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

    public CloudLink create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudLinks()
                .createOrUpdate(resourceGroupName, privateCloudName, cloudLinkName, this.innerModel(), Context.NONE);
        return this;
    }

    public CloudLink create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudLinks()
                .createOrUpdate(resourceGroupName, privateCloudName, cloudLinkName, this.innerModel(), context);
        return this;
    }

    CloudLinkImpl(String name, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = new CloudLinkInner();
        this.serviceManager = serviceManager;
        this.cloudLinkName = name;
    }

    public CloudLinkImpl update() {
        return this;
    }

    public CloudLink apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudLinks()
                .createOrUpdate(resourceGroupName, privateCloudName, cloudLinkName, this.innerModel(), Context.NONE);
        return this;
    }

    public CloudLink apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudLinks()
                .createOrUpdate(resourceGroupName, privateCloudName, cloudLinkName, this.innerModel(), context);
        return this;
    }

    CloudLinkImpl(CloudLinkInner 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.cloudLinkName = Utils.getValueFromIdByName(innerObject.id(), "cloudLinks");
    }

    public CloudLink refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudLinks()
                .getWithResponse(resourceGroupName, privateCloudName, cloudLinkName, Context.NONE)
                .getValue();
        return this;
    }

    public CloudLink refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudLinks()
                .getWithResponse(resourceGroupName, privateCloudName, cloudLinkName, context)
                .getValue();
        return this;
    }

    public CloudLinkImpl withLinkedCloud(String linkedCloud) {
        this.innerModel().withLinkedCloud(linkedCloud);
        return this;
    }
}
