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

package azure.resourcemanager.multiservice.combined.implementation;

import azure.resourcemanager.multiservice.combined.fluent.models.DiskInner;
import azure.resourcemanager.multiservice.combined.models.Disk;
import azure.resourcemanager.multiservice.combined.models.DiskProperties;
import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import java.util.Collections;
import java.util.Map;

public final class DiskImpl implements Disk, Disk.Definition, Disk.Update {
    private DiskInner innerObject;

    private final azure.resourcemanager.multiservice.combined.CombinedManager 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 DiskProperties properties() {
        return this.innerModel().properties();
    }

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private azure.resourcemanager.multiservice.combined.CombinedManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String diskName;

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

    public Disk create() {
        this.innerObject = serviceManager.serviceClient()
            .getDisks()
            .createOrUpdate(resourceGroupName, diskName, this.innerModel(), Context.NONE);
        return this;
    }

    public Disk create(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getDisks()
            .createOrUpdate(resourceGroupName, diskName, this.innerModel(), context);
        return this;
    }

    DiskImpl(String name, azure.resourcemanager.multiservice.combined.CombinedManager serviceManager) {
        this.innerObject = new DiskInner();
        this.serviceManager = serviceManager;
        this.diskName = name;
    }

    public DiskImpl update() {
        return this;
    }

    public Disk apply() {
        this.innerObject = serviceManager.serviceClient()
            .getDisks()
            .createOrUpdate(resourceGroupName, diskName, this.innerModel(), Context.NONE);
        return this;
    }

    public Disk apply(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getDisks()
            .createOrUpdate(resourceGroupName, diskName, this.innerModel(), context);
        return this;
    }

    DiskImpl(DiskInner innerObject, azure.resourcemanager.multiservice.combined.CombinedManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.diskName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "disks");
    }

    public Disk refresh() {
        this.innerObject = serviceManager.serviceClient()
            .getDisks()
            .getByResourceGroupWithResponse(resourceGroupName, diskName, Context.NONE)
            .getValue();
        return this;
    }

    public Disk refresh(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getDisks()
            .getByResourceGroupWithResponse(resourceGroupName, diskName, context)
            .getValue();
        return this;
    }

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

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

    public DiskImpl withTags(Map<String, String> tags) {
        this.innerModel().withTags(tags);
        return this;
    }

    public DiskImpl withProperties(DiskProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
