// 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.CustomDomainInner;
import com.azure.resourcemanager.webpubsub.models.CustomDomain;
import com.azure.resourcemanager.webpubsub.models.ProvisioningState;
import com.azure.resourcemanager.webpubsub.models.ResourceReference;

public final class CustomDomainImpl implements CustomDomain, CustomDomain.Definition, CustomDomain.Update {
    private CustomDomainInner 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 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.webpubsub.WebPubSubManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String resourceName;

    private String name;

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

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

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

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

    public CustomDomainImpl update() {
        return this;
    }

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

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

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

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

    public CustomDomain refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWebPubSubCustomDomains()
                .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;
    }
}
