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

package com.azure.resourcemanager.dynatrace.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.dynatrace.fluent.models.DynatraceSingleSignOnResourceInner;
import com.azure.resourcemanager.dynatrace.models.DynatraceSingleSignOnResource;
import com.azure.resourcemanager.dynatrace.models.ProvisioningState;
import com.azure.resourcemanager.dynatrace.models.SingleSignOnStates;
import java.util.Collections;
import java.util.List;

public final class DynatraceSingleSignOnResourceImpl
    implements DynatraceSingleSignOnResource,
        DynatraceSingleSignOnResource.Definition,
        DynatraceSingleSignOnResource.Update {
    private DynatraceSingleSignOnResourceInner innerObject;

    private final com.azure.resourcemanager.dynatrace.DynatraceManager 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 SingleSignOnStates singleSignOnState() {
        return this.innerModel().singleSignOnState();
    }

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

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

    public List<String> aadDomains() {
        List<String> inner = this.innerModel().aadDomains();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public ProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.dynatrace.DynatraceManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String monitorName;

    private String configurationName;

    public DynatraceSingleSignOnResourceImpl withExistingMonitor(String resourceGroupName, String monitorName) {
        this.resourceGroupName = resourceGroupName;
        this.monitorName = monitorName;
        return this;
    }

    public DynatraceSingleSignOnResource create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSingleSignOns()
                .createOrUpdate(resourceGroupName, monitorName, configurationName, this.innerModel(), Context.NONE);
        return this;
    }

    public DynatraceSingleSignOnResource create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSingleSignOns()
                .createOrUpdate(resourceGroupName, monitorName, configurationName, this.innerModel(), context);
        return this;
    }

    DynatraceSingleSignOnResourceImpl(
        String name, com.azure.resourcemanager.dynatrace.DynatraceManager serviceManager) {
        this.innerObject = new DynatraceSingleSignOnResourceInner();
        this.serviceManager = serviceManager;
        this.configurationName = name;
    }

    public DynatraceSingleSignOnResourceImpl update() {
        return this;
    }

    public DynatraceSingleSignOnResource apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSingleSignOns()
                .createOrUpdate(resourceGroupName, monitorName, configurationName, this.innerModel(), Context.NONE);
        return this;
    }

    public DynatraceSingleSignOnResource apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSingleSignOns()
                .createOrUpdate(resourceGroupName, monitorName, configurationName, this.innerModel(), context);
        return this;
    }

    DynatraceSingleSignOnResourceImpl(
        DynatraceSingleSignOnResourceInner innerObject,
        com.azure.resourcemanager.dynatrace.DynatraceManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.monitorName = Utils.getValueFromIdByName(innerObject.id(), "monitors");
        this.configurationName = Utils.getValueFromIdByName(innerObject.id(), "singleSignOnConfigurations");
    }

    public DynatraceSingleSignOnResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSingleSignOns()
                .getWithResponse(resourceGroupName, monitorName, configurationName, Context.NONE)
                .getValue();
        return this;
    }

    public DynatraceSingleSignOnResource refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSingleSignOns()
                .getWithResponse(resourceGroupName, monitorName, configurationName, context)
                .getValue();
        return this;
    }

    public DynatraceSingleSignOnResourceImpl withSingleSignOnState(SingleSignOnStates singleSignOnState) {
        this.innerModel().withSingleSignOnState(singleSignOnState);
        return this;
    }

    public DynatraceSingleSignOnResourceImpl withEnterpriseAppId(String enterpriseAppId) {
        this.innerModel().withEnterpriseAppId(enterpriseAppId);
        return this;
    }

    public DynatraceSingleSignOnResourceImpl withSingleSignOnUrl(String singleSignOnUrl) {
        this.innerModel().withSingleSignOnUrl(singleSignOnUrl);
        return this;
    }

    public DynatraceSingleSignOnResourceImpl withAadDomains(List<String> aadDomains) {
        this.innerModel().withAadDomains(aadDomains);
        return this;
    }
}
