// 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.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.netapp.fluent.models.CapacityPoolInner;
import com.azure.resourcemanager.netapp.models.CapacityPool;
import com.azure.resourcemanager.netapp.models.CapacityPoolPatch;
import com.azure.resourcemanager.netapp.models.EncryptionType;
import com.azure.resourcemanager.netapp.models.QosType;
import com.azure.resourcemanager.netapp.models.ServiceLevel;
import java.util.Collections;
import java.util.Map;

public final class CapacityPoolImpl implements CapacityPool, CapacityPool.Definition, CapacityPool.Update {
    private CapacityPoolInner 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 String location() {
        return this.innerModel().location();
    }

    public Map<String, String> tags() {
        Map<String, String> inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

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

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

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

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

    public ServiceLevel serviceLevel() {
        return this.innerModel().serviceLevel();
    }

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

    public Float totalThroughputMibps() {
        return this.innerModel().totalThroughputMibps();
    }

    public Float utilizedThroughputMibps() {
        return this.innerModel().utilizedThroughputMibps();
    }

    public QosType qosType() {
        return this.innerModel().qosType();
    }

    public Boolean coolAccess() {
        return this.innerModel().coolAccess();
    }

    public EncryptionType encryptionType() {
        return this.innerModel().encryptionType();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String accountName;

    private String poolName;

    private CapacityPoolPatch updateBody;

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

    public CapacityPool create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPools()
                .createOrUpdate(resourceGroupName, accountName, poolName, this.innerModel(), Context.NONE);
        return this;
    }

    public CapacityPool create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPools()
                .createOrUpdate(resourceGroupName, accountName, poolName, this.innerModel(), context);
        return this;
    }

    CapacityPoolImpl(String name, com.azure.resourcemanager.netapp.NetAppFilesManager serviceManager) {
        this.innerObject = new CapacityPoolInner();
        this.serviceManager = serviceManager;
        this.poolName = name;
    }

    public CapacityPoolImpl update() {
        this.updateBody = new CapacityPoolPatch();
        return this;
    }

    public CapacityPool apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPools()
                .update(resourceGroupName, accountName, poolName, updateBody, Context.NONE);
        return this;
    }

    public CapacityPool apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPools()
                .update(resourceGroupName, accountName, poolName, updateBody, context);
        return this;
    }

    CapacityPoolImpl(
        CapacityPoolInner 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");
    }

    public CapacityPool refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPools()
                .getWithResponse(resourceGroupName, accountName, poolName, Context.NONE)
                .getValue();
        return this;
    }

    public CapacityPool refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPools()
                .getWithResponse(resourceGroupName, accountName, poolName, context)
                .getValue();
        return this;
    }

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

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

    public CapacityPoolImpl withSize(long size) {
        this.innerModel().withSize(size);
        return this;
    }

    public CapacityPoolImpl withServiceLevel(ServiceLevel serviceLevel) {
        this.innerModel().withServiceLevel(serviceLevel);
        return this;
    }

    public CapacityPoolImpl withTags(Map<String, String> tags) {
        if (isInCreateMode()) {
            this.innerModel().withTags(tags);
            return this;
        } else {
            this.updateBody.withTags(tags);
            return this;
        }
    }

    public CapacityPoolImpl withQosType(QosType qosType) {
        if (isInCreateMode()) {
            this.innerModel().withQosType(qosType);
            return this;
        } else {
            this.updateBody.withQosType(qosType);
            return this;
        }
    }

    public CapacityPoolImpl withCoolAccess(Boolean coolAccess) {
        if (isInCreateMode()) {
            this.innerModel().withCoolAccess(coolAccess);
            return this;
        } else {
            this.updateBody.withCoolAccess(coolAccess);
            return this;
        }
    }

    public CapacityPoolImpl withEncryptionType(EncryptionType encryptionType) {
        this.innerModel().withEncryptionType(encryptionType);
        return this;
    }

    public CapacityPoolImpl withSize(Long size) {
        this.updateBody.withSize(size);
        return this;
    }

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