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

package com.azure.resourcemanager.digitaltwins.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.digitaltwins.fluent.models.DigitalTwinsEndpointResourceInner;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsEndpointResource;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsEndpointResourceProperties;

public final class DigitalTwinsEndpointResourceImpl
    implements DigitalTwinsEndpointResource,
        DigitalTwinsEndpointResource.Definition,
        DigitalTwinsEndpointResource.Update {
    private DigitalTwinsEndpointResourceInner innerObject;

    private final com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager serviceManager;

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String resourceName;

    private String endpointName;

    public DigitalTwinsEndpointResourceImpl withExistingDigitalTwinsInstance(
        String resourceGroupName, String resourceName) {
        this.resourceGroupName = resourceGroupName;
        this.resourceName = resourceName;
        return this;
    }

    public DigitalTwinsEndpointResource create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwinsEndpoints()
                .createOrUpdate(resourceGroupName, resourceName, endpointName, this.innerModel(), Context.NONE);
        return this;
    }

    public DigitalTwinsEndpointResource create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwinsEndpoints()
                .createOrUpdate(resourceGroupName, resourceName, endpointName, this.innerModel(), context);
        return this;
    }

    DigitalTwinsEndpointResourceImpl(
        String name, com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager serviceManager) {
        this.innerObject = new DigitalTwinsEndpointResourceInner();
        this.serviceManager = serviceManager;
        this.endpointName = name;
    }

    public DigitalTwinsEndpointResourceImpl update() {
        return this;
    }

    public DigitalTwinsEndpointResource apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwinsEndpoints()
                .createOrUpdate(resourceGroupName, resourceName, endpointName, this.innerModel(), Context.NONE);
        return this;
    }

    public DigitalTwinsEndpointResource apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwinsEndpoints()
                .createOrUpdate(resourceGroupName, resourceName, endpointName, this.innerModel(), context);
        return this;
    }

    DigitalTwinsEndpointResourceImpl(
        DigitalTwinsEndpointResourceInner innerObject,
        com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.resourceName = Utils.getValueFromIdByName(innerObject.id(), "digitalTwinsInstances");
        this.endpointName = Utils.getValueFromIdByName(innerObject.id(), "endpoints");
    }

    public DigitalTwinsEndpointResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwinsEndpoints()
                .getWithResponse(resourceGroupName, resourceName, endpointName, Context.NONE)
                .getValue();
        return this;
    }

    public DigitalTwinsEndpointResource refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwinsEndpoints()
                .getWithResponse(resourceGroupName, resourceName, endpointName, context)
                .getValue();
        return this;
    }

    public DigitalTwinsEndpointResourceImpl withProperties(DigitalTwinsEndpointResourceProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
