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

package com.azure.resourcemanager.signalr.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.signalr.fluent.models.CustomDomainInner;
import com.azure.resourcemanager.signalr.models.CustomDomain;
import com.azure.resourcemanager.signalr.models.ProvisioningState;
import com.azure.resourcemanager.signalr.models.ResourceReference;

public final class CustomDomainImpl implements CustomDomain, CustomDomain.Definition, CustomDomain.Update {
    private CustomDomainInner innerObject;

    private final com.azure.resourcemanager.signalr.SignalRManager 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 ProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

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

    public ResourceReference customCertificate() {
        return this.innerModel().customCertificate();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.signalr.SignalRManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String resourceName;

    private String name;

    public CustomDomainImpl withExistingSignalR(String resourceGroupName, String resourceName) {
        this.resourceGroupName = resourceGroupName;
        this.resourceName = resourceName;
        return this;
    }

    public CustomDomain create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSignalRCustomDomains()
                .createOrUpdate(resourceGroupName, resourceName, name, this.innerModel(), Context.NONE);
        return this;
    }

    public CustomDomain create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSignalRCustomDomains()
                .createOrUpdate(resourceGroupName, resourceName, name, this.innerModel(), context);
        return this;
    }

    CustomDomainImpl(String name, com.azure.resourcemanager.signalr.SignalRManager serviceManager) {
        this.innerObject = new CustomDomainInner();
        this.serviceManager = serviceManager;
        this.name = name;
    }

    public CustomDomainImpl update() {
        return this;
    }

    public CustomDomain apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSignalRCustomDomains()
                .createOrUpdate(resourceGroupName, resourceName, name, this.innerModel(), Context.NONE);
        return this;
    }

    public CustomDomain apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSignalRCustomDomains()
                .createOrUpdate(resourceGroupName, resourceName, name, this.innerModel(), context);
        return this;
    }

    CustomDomainImpl(CustomDomainInner innerObject, com.azure.resourcemanager.signalr.SignalRManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.resourceName = Utils.getValueFromIdByName(innerObject.id(), "signalR");
        this.name = Utils.getValueFromIdByName(innerObject.id(), "customDomains");
    }

    public CustomDomain refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSignalRCustomDomains()
                .getWithResponse(resourceGroupName, resourceName, name, Context.NONE)
                .getValue();
        return this;
    }

    public CustomDomain refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSignalRCustomDomains()
                .getWithResponse(resourceGroupName, resourceName, name, context)
                .getValue();
        return this;
    }

    public CustomDomainImpl withDomainName(String domainName) {
        this.innerModel().withDomainName(domainName);
        return this;
    }

    public CustomDomainImpl withCustomCertificate(ResourceReference customCertificate) {
        this.innerModel().withCustomCertificate(customCertificate);
        return this;
    }
}
