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

package com.azure.resourcemanager.networkcloud.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.networkcloud.fluent.models.StorageApplianceInner;
import com.azure.resourcemanager.networkcloud.models.AdministrativeCredentials;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import com.azure.resourcemanager.networkcloud.models.RemoteVendorManagementFeature;
import com.azure.resourcemanager.networkcloud.models.RemoteVendorManagementStatus;
import com.azure.resourcemanager.networkcloud.models.StorageAppliance;
import com.azure.resourcemanager.networkcloud.models.StorageApplianceDetailedStatus;
import com.azure.resourcemanager.networkcloud.models.StorageApplianceEnableRemoteVendorManagementParameters;
import com.azure.resourcemanager.networkcloud.models.StorageAppliancePatchParameters;
import com.azure.resourcemanager.networkcloud.models.StorageApplianceProvisioningState;
import com.azure.resourcemanager.networkcloud.models.StorageApplianceRunReadCommandsParameters;
import java.util.Collections;
import java.util.Map;

public final class StorageApplianceImpl
    implements StorageAppliance, StorageAppliance.Definition, StorageAppliance.Update {
    private StorageApplianceInner innerObject;

    private final com.azure.resourcemanager.networkcloud.NetworkCloudManager 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 ExtendedLocation extendedLocation() {
        return this.innerModel().extendedLocation();
    }

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

    public AdministrativeCredentials administratorCredentials() {
        return this.innerModel().administratorCredentials();
    }

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

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

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

    public StorageApplianceDetailedStatus detailedStatus() {
        return this.innerModel().detailedStatus();
    }

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

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

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

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

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

    public RemoteVendorManagementFeature remoteVendorManagementFeature() {
        return this.innerModel().remoteVendorManagementFeature();
    }

    public RemoteVendorManagementStatus remoteVendorManagementStatus() {
        return this.innerModel().remoteVendorManagementStatus();
    }

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.networkcloud.NetworkCloudManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String storageApplianceName;

    private StorageAppliancePatchParameters updateStorageApplianceUpdateParameters;

    public StorageApplianceImpl withExistingResourceGroup(String resourceGroupName) {
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public StorageAppliance create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getStorageAppliances()
                .createOrUpdate(resourceGroupName, storageApplianceName, this.innerModel(), Context.NONE);
        return this;
    }

    public StorageAppliance create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getStorageAppliances()
                .createOrUpdate(resourceGroupName, storageApplianceName, this.innerModel(), context);
        return this;
    }

    StorageApplianceImpl(String name, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = new StorageApplianceInner();
        this.serviceManager = serviceManager;
        this.storageApplianceName = name;
    }

    public StorageApplianceImpl update() {
        this.updateStorageApplianceUpdateParameters = new StorageAppliancePatchParameters();
        return this;
    }

    public StorageAppliance apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getStorageAppliances()
                .update(resourceGroupName, storageApplianceName, updateStorageApplianceUpdateParameters, Context.NONE);
        return this;
    }

    public StorageAppliance apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getStorageAppliances()
                .update(resourceGroupName, storageApplianceName, updateStorageApplianceUpdateParameters, context);
        return this;
    }

    StorageApplianceImpl(
        StorageApplianceInner innerObject, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.storageApplianceName = Utils.getValueFromIdByName(innerObject.id(), "storageAppliances");
    }

    public StorageAppliance refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getStorageAppliances()
                .getByResourceGroupWithResponse(resourceGroupName, storageApplianceName, Context.NONE)
                .getValue();
        return this;
    }

    public StorageAppliance refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getStorageAppliances()
                .getByResourceGroupWithResponse(resourceGroupName, storageApplianceName, context)
                .getValue();
        return this;
    }

    public void disableRemoteVendorManagement() {
        serviceManager.storageAppliances().disableRemoteVendorManagement(resourceGroupName, storageApplianceName);
    }

    public void disableRemoteVendorManagement(Context context) {
        serviceManager
            .storageAppliances()
            .disableRemoteVendorManagement(resourceGroupName, storageApplianceName, context);
    }

    public void enableRemoteVendorManagement() {
        serviceManager.storageAppliances().enableRemoteVendorManagement(resourceGroupName, storageApplianceName);
    }

    public void enableRemoteVendorManagement(
        StorageApplianceEnableRemoteVendorManagementParameters storageApplianceEnableRemoteVendorManagementParameters,
        Context context) {
        serviceManager
            .storageAppliances()
            .enableRemoteVendorManagement(
                resourceGroupName,
                storageApplianceName,
                storageApplianceEnableRemoteVendorManagementParameters,
                context);
    }

    public void runReadCommands(StorageApplianceRunReadCommandsParameters storageApplianceRunReadCommandsParameters) {
        serviceManager
            .storageAppliances()
            .runReadCommands(resourceGroupName, storageApplianceName, storageApplianceRunReadCommandsParameters);
    }

    public void runReadCommands(
        StorageApplianceRunReadCommandsParameters storageApplianceRunReadCommandsParameters, Context context) {
        serviceManager
            .storageAppliances()
            .runReadCommands(
                resourceGroupName, storageApplianceName, storageApplianceRunReadCommandsParameters, context);
    }

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

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

    public StorageApplianceImpl withExtendedLocation(ExtendedLocation extendedLocation) {
        this.innerModel().withExtendedLocation(extendedLocation);
        return this;
    }

    public StorageApplianceImpl withAdministratorCredentials(AdministrativeCredentials administratorCredentials) {
        this.innerModel().withAdministratorCredentials(administratorCredentials);
        return this;
    }

    public StorageApplianceImpl withRackId(String rackId) {
        this.innerModel().withRackId(rackId);
        return this;
    }

    public StorageApplianceImpl withRackSlot(long rackSlot) {
        this.innerModel().withRackSlot(rackSlot);
        return this;
    }

    public StorageApplianceImpl withSerialNumber(String serialNumber) {
        if (isInCreateMode()) {
            this.innerModel().withSerialNumber(serialNumber);
            return this;
        } else {
            this.updateStorageApplianceUpdateParameters.withSerialNumber(serialNumber);
            return this;
        }
    }

    public StorageApplianceImpl withStorageApplianceSkuId(String storageApplianceSkuId) {
        this.innerModel().withStorageApplianceSkuId(storageApplianceSkuId);
        return this;
    }

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

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