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

package com.azure.resourcemanager.qumulo.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.qumulo.fluent.models.FileSystemResourceInner;
import com.azure.resourcemanager.qumulo.models.FileSystemResource;
import com.azure.resourcemanager.qumulo.models.FileSystemResourceUpdate;
import com.azure.resourcemanager.qumulo.models.FileSystemResourceUpdateProperties;
import com.azure.resourcemanager.qumulo.models.ManagedServiceIdentity;
import com.azure.resourcemanager.qumulo.models.MarketplaceDetails;
import com.azure.resourcemanager.qumulo.models.ProvisioningState;
import com.azure.resourcemanager.qumulo.models.StorageSku;
import com.azure.resourcemanager.qumulo.models.UserDetails;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class FileSystemResourceImpl
    implements FileSystemResource, FileSystemResource.Definition, FileSystemResource.Update {
    private FileSystemResourceInner innerObject;

    private final com.azure.resourcemanager.qumulo.QumuloManager 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 ManagedServiceIdentity identity() {
        return this.innerModel().identity();
    }

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

    public MarketplaceDetails marketplaceDetails() {
        return this.innerModel().marketplaceDetails();
    }

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

    public StorageSku storageSku() {
        return this.innerModel().storageSku();
    }

    public UserDetails userDetails() {
        return this.innerModel().userDetails();
    }

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

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

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

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

    public int initialCapacity() {
        return this.innerModel().initialCapacity();
    }

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.qumulo.QumuloManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String fileSystemName;

    private FileSystemResourceUpdate updateProperties;

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

    public FileSystemResource create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getFileSystems()
                .createOrUpdate(resourceGroupName, fileSystemName, this.innerModel(), Context.NONE);
        return this;
    }

    public FileSystemResource create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getFileSystems()
                .createOrUpdate(resourceGroupName, fileSystemName, this.innerModel(), context);
        return this;
    }

    FileSystemResourceImpl(String name, com.azure.resourcemanager.qumulo.QumuloManager serviceManager) {
        this.innerObject = new FileSystemResourceInner();
        this.serviceManager = serviceManager;
        this.fileSystemName = name;
    }

    public FileSystemResourceImpl update() {
        this.updateProperties = new FileSystemResourceUpdate();
        return this;
    }

    public FileSystemResource apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getFileSystems()
                .updateWithResponse(resourceGroupName, fileSystemName, updateProperties, Context.NONE)
                .getValue();
        return this;
    }

    public FileSystemResource apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getFileSystems()
                .updateWithResponse(resourceGroupName, fileSystemName, updateProperties, context)
                .getValue();
        return this;
    }

    FileSystemResourceImpl(
        FileSystemResourceInner innerObject, com.azure.resourcemanager.qumulo.QumuloManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.fileSystemName = Utils.getValueFromIdByName(innerObject.id(), "fileSystems");
    }

    public FileSystemResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getFileSystems()
                .getByResourceGroupWithResponse(resourceGroupName, fileSystemName, Context.NONE)
                .getValue();
        return this;
    }

    public FileSystemResource refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getFileSystems()
                .getByResourceGroupWithResponse(resourceGroupName, fileSystemName, context)
                .getValue();
        return this;
    }

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

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

    public FileSystemResourceImpl withMarketplaceDetails(MarketplaceDetails marketplaceDetails) {
        this.innerModel().withMarketplaceDetails(marketplaceDetails);
        return this;
    }

    public FileSystemResourceImpl withStorageSku(StorageSku storageSku) {
        this.innerModel().withStorageSku(storageSku);
        return this;
    }

    public FileSystemResourceImpl withUserDetails(UserDetails userDetails) {
        this.innerModel().withUserDetails(userDetails);
        return this;
    }

    public FileSystemResourceImpl withDelegatedSubnetId(String delegatedSubnetId) {
        this.innerModel().withDelegatedSubnetId(delegatedSubnetId);
        return this;
    }

    public FileSystemResourceImpl withAdminPassword(String adminPassword) {
        this.innerModel().withAdminPassword(adminPassword);
        return this;
    }

    public FileSystemResourceImpl withInitialCapacity(int initialCapacity) {
        this.innerModel().withInitialCapacity(initialCapacity);
        return this;
    }

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

    public FileSystemResourceImpl withIdentity(ManagedServiceIdentity identity) {
        if (isInCreateMode()) {
            this.innerModel().withIdentity(identity);
            return this;
        } else {
            this.updateProperties.withIdentity(identity);
            return this;
        }
    }

    public FileSystemResourceImpl withClusterLoginUrl(String clusterLoginUrl) {
        this.innerModel().withClusterLoginUrl(clusterLoginUrl);
        return this;
    }

    public FileSystemResourceImpl withPrivateIPs(List<String> privateIPs) {
        this.innerModel().withPrivateIPs(privateIPs);
        return this;
    }

    public FileSystemResourceImpl withAvailabilityZone(String availabilityZone) {
        this.innerModel().withAvailabilityZone(availabilityZone);
        return this;
    }

    public FileSystemResourceImpl withProperties(FileSystemResourceUpdateProperties properties) {
        this.updateProperties.withProperties(properties);
        return this;
    }

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