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

package com.azure.resourcemanager.providerhub.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.providerhub.fluent.models.NotificationRegistrationInner;
import com.azure.resourcemanager.providerhub.models.NotificationRegistration;
import com.azure.resourcemanager.providerhub.models.NotificationRegistrationProperties;

public final class NotificationRegistrationImpl
    implements NotificationRegistration, NotificationRegistration.Definition, NotificationRegistration.Update {
    private NotificationRegistrationInner innerObject;

    private final com.azure.resourcemanager.providerhub.ProviderHubManager serviceManager;

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

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

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

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

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

    private com.azure.resourcemanager.providerhub.ProviderHubManager manager() {
        return this.serviceManager;
    }

    private String providerNamespace;

    private String notificationRegistrationName;

    public NotificationRegistrationImpl withExistingProviderRegistration(String providerNamespace) {
        this.providerNamespace = providerNamespace;
        return this;
    }

    public NotificationRegistration create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNotificationRegistrations()
                .createOrUpdateWithResponse(
                    providerNamespace, notificationRegistrationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public NotificationRegistration create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNotificationRegistrations()
                .createOrUpdateWithResponse(providerNamespace, notificationRegistrationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    NotificationRegistrationImpl(String name, com.azure.resourcemanager.providerhub.ProviderHubManager serviceManager) {
        this.innerObject = new NotificationRegistrationInner();
        this.serviceManager = serviceManager;
        this.notificationRegistrationName = name;
    }

    public NotificationRegistrationImpl update() {
        return this;
    }

    public NotificationRegistration apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNotificationRegistrations()
                .createOrUpdateWithResponse(
                    providerNamespace, notificationRegistrationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public NotificationRegistration apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNotificationRegistrations()
                .createOrUpdateWithResponse(providerNamespace, notificationRegistrationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    NotificationRegistrationImpl(
        NotificationRegistrationInner innerObject,
        com.azure.resourcemanager.providerhub.ProviderHubManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.providerNamespace = Utils.getValueFromIdByName(innerObject.id(), "providerRegistrations");
        this.notificationRegistrationName = Utils.getValueFromIdByName(innerObject.id(), "notificationRegistrations");
    }

    public NotificationRegistration refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNotificationRegistrations()
                .getWithResponse(providerNamespace, notificationRegistrationName, Context.NONE)
                .getValue();
        return this;
    }

    public NotificationRegistration refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNotificationRegistrations()
                .getWithResponse(providerNamespace, notificationRegistrationName, context)
                .getValue();
        return this;
    }

    public NotificationRegistrationImpl withProperties(NotificationRegistrationProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
