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

package azure.resourcemanager.resources.implementation;

import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner;
import azure.resourcemanager.resources.models.ExtensionsResource;
import azure.resourcemanager.resources.models.ExtensionsResourceProperties;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;

public final class ExtensionsResourceImpl
    implements ExtensionsResource, ExtensionsResource.Definition, ExtensionsResource.Update {
    private ExtensionsResourceInner innerObject;

    private final azure.resourcemanager.resources.ResourcesManager serviceManager;

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

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

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

    public ExtensionsResourceProperties properties() {
        return this.innerModel().properties();
    }

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

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

    private azure.resourcemanager.resources.ResourcesManager manager() {
        return this.serviceManager;
    }

    private String resourceUri;

    private String extensionsResourceName;

    public ExtensionsResourceImpl withExistingResourceUri(String resourceUri) {
        this.resourceUri = resourceUri;
        return this;
    }

    public ExtensionsResource create() {
        this.innerObject = serviceManager.serviceClient()
            .getExtensionsResources()
            .createOrUpdate(resourceUri, extensionsResourceName, this.innerModel(), Context.NONE);
        return this;
    }

    public ExtensionsResource create(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getExtensionsResources()
            .createOrUpdate(resourceUri, extensionsResourceName, this.innerModel(), context);
        return this;
    }

    ExtensionsResourceImpl(String name, azure.resourcemanager.resources.ResourcesManager serviceManager) {
        this.innerObject = new ExtensionsResourceInner();
        this.serviceManager = serviceManager;
        this.extensionsResourceName = name;
    }

    public ExtensionsResourceImpl update() {
        return this;
    }

    public ExtensionsResource apply() {
        this.innerObject = serviceManager.serviceClient()
            .getExtensionsResources()
            .updateWithResponse(resourceUri, extensionsResourceName, this.innerModel(), Context.NONE)
            .getValue();
        return this;
    }

    public ExtensionsResource apply(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getExtensionsResources()
            .updateWithResponse(resourceUri, extensionsResourceName, this.innerModel(), context)
            .getValue();
        return this;
    }

    ExtensionsResourceImpl(ExtensionsResourceInner innerObject,
        azure.resourcemanager.resources.ResourcesManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceUri = ResourceManagerUtils.getValueFromIdByParameterName(innerObject.id(),
            "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}",
            "resourceUri");
        this.extensionsResourceName = ResourceManagerUtils.getValueFromIdByParameterName(innerObject.id(),
            "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}",
            "extensionsResourceName");
    }

    public ExtensionsResource refresh() {
        this.innerObject = serviceManager.serviceClient()
            .getExtensionsResources()
            .getWithResponse(resourceUri, extensionsResourceName, Context.NONE)
            .getValue();
        return this;
    }

    public ExtensionsResource refresh(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getExtensionsResources()
            .getWithResponse(resourceUri, extensionsResourceName, context)
            .getValue();
        return this;
    }

    public ExtensionsResourceImpl withProperties(ExtensionsResourceProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
