// 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.WorkloadNetworkVMGroupInner;
import com.azure.resourcemanager.avs.models.VMGroupStatusEnum;
import com.azure.resourcemanager.avs.models.WorkloadNetworkVMGroup;
import com.azure.resourcemanager.avs.models.WorkloadNetworkVMGroupProvisioningState;
import java.util.Collections;
import java.util.List;

public final class WorkloadNetworkVMGroupImpl
    implements WorkloadNetworkVMGroup, WorkloadNetworkVMGroup.Definition, WorkloadNetworkVMGroup.Update {
    private WorkloadNetworkVMGroupInner 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 String displayName() {
        return this.innerModel().displayName();
    }

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

    public VMGroupStatusEnum status() {
        return this.innerModel().status();
    }

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

    public Long revision() {
        return this.innerModel().revision();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String privateCloudName;

    private String vmGroupId;

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

    public WorkloadNetworkVMGroup create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .createVMGroup(resourceGroupName, privateCloudName, vmGroupId, this.innerModel(), Context.NONE);
        return this;
    }

    public WorkloadNetworkVMGroup create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .createVMGroup(resourceGroupName, privateCloudName, vmGroupId, this.innerModel(), context);
        return this;
    }

    WorkloadNetworkVMGroupImpl(String name, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = new WorkloadNetworkVMGroupInner();
        this.serviceManager = serviceManager;
        this.vmGroupId = name;
    }

    public WorkloadNetworkVMGroupImpl update() {
        return this;
    }

    public WorkloadNetworkVMGroup apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .updateVMGroup(resourceGroupName, privateCloudName, vmGroupId, this.innerModel(), Context.NONE);
        return this;
    }

    public WorkloadNetworkVMGroup apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .updateVMGroup(resourceGroupName, privateCloudName, vmGroupId, this.innerModel(), context);
        return this;
    }

    WorkloadNetworkVMGroupImpl(
        WorkloadNetworkVMGroupInner 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.vmGroupId = Utils.getValueFromIdByName(innerObject.id(), "vmGroups");
    }

    public WorkloadNetworkVMGroup refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .getVMGroupWithResponse(resourceGroupName, privateCloudName, vmGroupId, Context.NONE)
                .getValue();
        return this;
    }

    public WorkloadNetworkVMGroup refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWorkloadNetworks()
                .getVMGroupWithResponse(resourceGroupName, privateCloudName, vmGroupId, context)
                .getValue();
        return this;
    }

    public WorkloadNetworkVMGroupImpl withDisplayName(String displayName) {
        this.innerModel().withDisplayName(displayName);
        return this;
    }

    public WorkloadNetworkVMGroupImpl withMembers(List<String> members) {
        this.innerModel().withMembers(members);
        return this;
    }

    public WorkloadNetworkVMGroupImpl withRevision(Long revision) {
        this.innerModel().withRevision(revision);
        return this;
    }
}
