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

package azure.resourcemanager.methodsubscriptionid.implementation;

import azure.resourcemanager.methodsubscriptionid.fluent.models.ResourceGroupResourceInner;
import azure.resourcemanager.methodsubscriptionid.models.ResourceGroupResource;
import azure.resourcemanager.methodsubscriptionid.models.ResourceGroupResourceProperties;
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 ResourceGroupResourceImpl
    implements ResourceGroupResource, ResourceGroupResource.Definition, ResourceGroupResource.Update {
    private ResourceGroupResourceInner innerObject;

    private final azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager 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 ResourceGroupResourceProperties 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 ResourceGroupResourceInner innerModel() {
        return this.innerObject;
    }

    private azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String resourceGroupResourceName;

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

    public ResourceGroupResource create() {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementResourceGroupResourceOperations()
            .putWithResponse(resourceGroupName, resourceGroupResourceName, this.innerModel(), Context.NONE)
            .getValue();
        return this;
    }

    public ResourceGroupResource create(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementResourceGroupResourceOperations()
            .putWithResponse(resourceGroupName, resourceGroupResourceName, this.innerModel(), context)
            .getValue();
        return this;
    }

    ResourceGroupResourceImpl(String name,
        azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager) {
        this.innerObject = new ResourceGroupResourceInner();
        this.serviceManager = serviceManager;
        this.resourceGroupResourceName = name;
    }

    public ResourceGroupResourceImpl update() {
        return this;
    }

    public ResourceGroupResource apply() {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementResourceGroupResourceOperations()
            .putWithResponse(resourceGroupName, resourceGroupResourceName, this.innerModel(), Context.NONE)
            .getValue();
        return this;
    }

    public ResourceGroupResource apply(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementResourceGroupResourceOperations()
            .putWithResponse(resourceGroupName, resourceGroupResourceName, this.innerModel(), context)
            .getValue();
        return this;
    }

    ResourceGroupResourceImpl(ResourceGroupResourceInner innerObject,
        azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.resourceGroupResourceName
            = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroupResources");
    }

    public ResourceGroupResource refresh() {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementResourceGroupResourceOperations()
            .getByResourceGroupWithResponse(resourceGroupName, resourceGroupResourceName, Context.NONE)
            .getValue();
        return this;
    }

    public ResourceGroupResource refresh(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementResourceGroupResourceOperations()
            .getByResourceGroupWithResponse(resourceGroupName, resourceGroupResourceName, context)
            .getValue();
        return this;
    }

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

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

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

    public ResourceGroupResourceImpl withProperties(ResourceGroupResourceProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
