// 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.ResourceTypeRegistrationInner;
import com.azure.resourcemanager.providerhub.models.ResourceTypeRegistration;
import com.azure.resourcemanager.providerhub.models.ResourceTypeRegistrationProperties;

public final class ResourceTypeRegistrationImpl
    implements ResourceTypeRegistration, ResourceTypeRegistration.Definition, ResourceTypeRegistration.Update {
    private ResourceTypeRegistrationInner 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 ResourceTypeRegistrationProperties properties() {
        return this.innerModel().properties();
    }

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

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

    private String providerNamespace;

    private String resourceType;

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

    public ResourceTypeRegistration create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getResourceTypeRegistrations()
                .createOrUpdate(providerNamespace, resourceType, this.innerModel(), Context.NONE);
        return this;
    }

    public ResourceTypeRegistration create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getResourceTypeRegistrations()
                .createOrUpdate(providerNamespace, resourceType, this.innerModel(), context);
        return this;
    }

    ResourceTypeRegistrationImpl(String name, com.azure.resourcemanager.providerhub.ProviderHubManager serviceManager) {
        this.innerObject = new ResourceTypeRegistrationInner();
        this.serviceManager = serviceManager;
        this.resourceType = name;
    }

    public ResourceTypeRegistrationImpl update() {
        return this;
    }

    public ResourceTypeRegistration apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getResourceTypeRegistrations()
                .createOrUpdate(providerNamespace, resourceType, this.innerModel(), Context.NONE);
        return this;
    }

    public ResourceTypeRegistration apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getResourceTypeRegistrations()
                .createOrUpdate(providerNamespace, resourceType, this.innerModel(), context);
        return this;
    }

    ResourceTypeRegistrationImpl(
        ResourceTypeRegistrationInner innerObject,
        com.azure.resourcemanager.providerhub.ProviderHubManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.providerNamespace = Utils.getValueFromIdByName(innerObject.id(), "providerRegistrations");
        this.resourceType = Utils.getValueFromIdByName(innerObject.id(), "resourcetypeRegistrations");
    }

    public ResourceTypeRegistration refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getResourceTypeRegistrations()
                .getWithResponse(providerNamespace, resourceType, Context.NONE)
                .getValue();
        return this;
    }

    public ResourceTypeRegistration refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getResourceTypeRegistrations()
                .getWithResponse(providerNamespace, resourceType, context)
                .getValue();
        return this;
    }

    public ResourceTypeRegistrationImpl withProperties(ResourceTypeRegistrationProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
