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

package com.azure.resourcemanager.webpubsub.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.webpubsub.fluent.models.WebPubSubHubInner;
import com.azure.resourcemanager.webpubsub.models.WebPubSubHub;
import com.azure.resourcemanager.webpubsub.models.WebPubSubHubProperties;

public final class WebPubSubHubImpl implements WebPubSubHub, WebPubSubHub.Definition, WebPubSubHub.Update {
    private WebPubSubHubInner innerObject;

    private final com.azure.resourcemanager.webpubsub.WebPubSubManager 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 WebPubSubHubProperties properties() {
        return this.innerModel().properties();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.webpubsub.WebPubSubManager manager() {
        return this.serviceManager;
    }

    private String hubName;

    private String resourceGroupName;

    private String resourceName;

    public WebPubSubHubImpl withExistingWebPubSub(String resourceGroupName, String resourceName) {
        this.resourceGroupName = resourceGroupName;
        this.resourceName = resourceName;
        return this;
    }

    public WebPubSubHub create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWebPubSubHubs()
                .createOrUpdate(hubName, resourceGroupName, resourceName, this.innerModel(), Context.NONE);
        return this;
    }

    public WebPubSubHub create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWebPubSubHubs()
                .createOrUpdate(hubName, resourceGroupName, resourceName, this.innerModel(), context);
        return this;
    }

    WebPubSubHubImpl(String name, com.azure.resourcemanager.webpubsub.WebPubSubManager serviceManager) {
        this.innerObject = new WebPubSubHubInner();
        this.serviceManager = serviceManager;
        this.hubName = name;
    }

    public WebPubSubHubImpl update() {
        return this;
    }

    public WebPubSubHub apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWebPubSubHubs()
                .createOrUpdate(hubName, resourceGroupName, resourceName, this.innerModel(), Context.NONE);
        return this;
    }

    public WebPubSubHub apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWebPubSubHubs()
                .createOrUpdate(hubName, resourceGroupName, resourceName, this.innerModel(), context);
        return this;
    }

    WebPubSubHubImpl(
        WebPubSubHubInner innerObject, com.azure.resourcemanager.webpubsub.WebPubSubManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.hubName = Utils.getValueFromIdByName(innerObject.id(), "hubs");
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.resourceName = Utils.getValueFromIdByName(innerObject.id(), "webPubSub");
    }

    public WebPubSubHub refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWebPubSubHubs()
                .getWithResponse(hubName, resourceGroupName, resourceName, Context.NONE)
                .getValue();
        return this;
    }

    public WebPubSubHub refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWebPubSubHubs()
                .getWithResponse(hubName, resourceGroupName, resourceName, context)
                .getValue();
        return this;
    }

    public WebPubSubHubImpl withProperties(WebPubSubHubProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
