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

package com.azure.resourcemanager.netapp.implementation;

import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.netapp.fluent.models.VolumeGroupDetailsInner;
import com.azure.resourcemanager.netapp.models.VolumeGroupDetails;
import com.azure.resourcemanager.netapp.models.VolumeGroupMetadata;
import com.azure.resourcemanager.netapp.models.VolumeGroupVolumeProperties;
import java.util.Collections;
import java.util.List;

public final class VolumeGroupDetailsImpl implements VolumeGroupDetails, VolumeGroupDetails.Definition {
    private VolumeGroupDetailsInner innerObject;

    private final com.azure.resourcemanager.netapp.NetAppFilesManager serviceManager;

    VolumeGroupDetailsImpl(
        VolumeGroupDetailsInner innerObject, com.azure.resourcemanager.netapp.NetAppFilesManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

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

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

    public VolumeGroupMetadata groupMetadata() {
        return this.innerModel().groupMetadata();
    }

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

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

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

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

    private com.azure.resourcemanager.netapp.NetAppFilesManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String accountName;

    private String volumeGroupName;

    public VolumeGroupDetailsImpl withExistingNetAppAccount(String resourceGroupName, String accountName) {
        this.resourceGroupName = resourceGroupName;
        this.accountName = accountName;
        return this;
    }

    public VolumeGroupDetails create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVolumeGroups()
                .create(resourceGroupName, accountName, volumeGroupName, this.innerModel(), Context.NONE);
        return this;
    }

    public VolumeGroupDetails create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVolumeGroups()
                .create(resourceGroupName, accountName, volumeGroupName, this.innerModel(), context);
        return this;
    }

    VolumeGroupDetailsImpl(String name, com.azure.resourcemanager.netapp.NetAppFilesManager serviceManager) {
        this.innerObject = new VolumeGroupDetailsInner();
        this.serviceManager = serviceManager;
        this.volumeGroupName = name;
    }

    public VolumeGroupDetails refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVolumeGroups()
                .getWithResponse(resourceGroupName, accountName, volumeGroupName, Context.NONE)
                .getValue();
        return this;
    }

    public VolumeGroupDetails refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVolumeGroups()
                .getWithResponse(resourceGroupName, accountName, volumeGroupName, context)
                .getValue();
        return this;
    }

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

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

    public VolumeGroupDetailsImpl withGroupMetadata(VolumeGroupMetadata groupMetadata) {
        this.innerModel().withGroupMetadata(groupMetadata);
        return this;
    }

    public VolumeGroupDetailsImpl withVolumes(List<VolumeGroupVolumeProperties> volumes) {
        this.innerModel().withVolumes(volumes);
        return this;
    }
}
