// 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.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.netapp.fluent.models.SubvolumeInfoInner;
import com.azure.resourcemanager.netapp.models.SubvolumeInfo;
import com.azure.resourcemanager.netapp.models.SubvolumeModel;
import com.azure.resourcemanager.netapp.models.SubvolumePatchRequest;

public final class SubvolumeInfoImpl implements SubvolumeInfo, SubvolumeInfo.Definition, SubvolumeInfo.Update {
    private SubvolumeInfoInner innerObject;

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

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

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

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

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String accountName;

    private String poolName;

    private String volumeName;

    private String subvolumeName;

    private SubvolumePatchRequest updateBody;

    public SubvolumeInfoImpl withExistingVolume(
        String resourceGroupName, String accountName, String poolName, String volumeName) {
        this.resourceGroupName = resourceGroupName;
        this.accountName = accountName;
        this.poolName = poolName;
        this.volumeName = volumeName;
        return this;
    }

    public SubvolumeInfo create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSubvolumes()
                .create(
                    resourceGroupName,
                    accountName,
                    poolName,
                    volumeName,
                    subvolumeName,
                    this.innerModel(),
                    Context.NONE);
        return this;
    }

    public SubvolumeInfo create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSubvolumes()
                .create(
                    resourceGroupName, accountName, poolName, volumeName, subvolumeName, this.innerModel(), context);
        return this;
    }

    SubvolumeInfoImpl(String name, com.azure.resourcemanager.netapp.NetAppFilesManager serviceManager) {
        this.innerObject = new SubvolumeInfoInner();
        this.serviceManager = serviceManager;
        this.subvolumeName = name;
    }

    public SubvolumeInfoImpl update() {
        this.updateBody = new SubvolumePatchRequest();
        return this;
    }

    public SubvolumeInfo apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSubvolumes()
                .update(resourceGroupName, accountName, poolName, volumeName, subvolumeName, updateBody, Context.NONE);
        return this;
    }

    public SubvolumeInfo apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSubvolumes()
                .update(resourceGroupName, accountName, poolName, volumeName, subvolumeName, updateBody, context);
        return this;
    }

    SubvolumeInfoImpl(
        SubvolumeInfoInner innerObject, com.azure.resourcemanager.netapp.NetAppFilesManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.accountName = Utils.getValueFromIdByName(innerObject.id(), "netAppAccounts");
        this.poolName = Utils.getValueFromIdByName(innerObject.id(), "capacityPools");
        this.volumeName = Utils.getValueFromIdByName(innerObject.id(), "volumes");
        this.subvolumeName = Utils.getValueFromIdByName(innerObject.id(), "subvolumes");
    }

    public SubvolumeInfo refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSubvolumes()
                .getWithResponse(resourceGroupName, accountName, poolName, volumeName, subvolumeName, Context.NONE)
                .getValue();
        return this;
    }

    public SubvolumeInfo refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSubvolumes()
                .getWithResponse(resourceGroupName, accountName, poolName, volumeName, subvolumeName, context)
                .getValue();
        return this;
    }

    public SubvolumeModel getMetadata() {
        return serviceManager
            .subvolumes()
            .getMetadata(resourceGroupName, accountName, poolName, volumeName, subvolumeName);
    }

    public SubvolumeModel getMetadata(Context context) {
        return serviceManager
            .subvolumes()
            .getMetadata(resourceGroupName, accountName, poolName, volumeName, subvolumeName, context);
    }

    public SubvolumeInfoImpl withPath(String path) {
        if (isInCreateMode()) {
            this.innerModel().withPath(path);
            return this;
        } else {
            this.updateBody.withPath(path);
            return this;
        }
    }

    public SubvolumeInfoImpl withSize(Long size) {
        if (isInCreateMode()) {
            this.innerModel().withSize(size);
            return this;
        } else {
            this.updateBody.withSize(size);
            return this;
        }
    }

    public SubvolumeInfoImpl withParentPath(String parentPath) {
        this.innerModel().withParentPath(parentPath);
        return this;
    }

    private boolean isInCreateMode() {
        return this.innerModel().id() == null;
    }
}
