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

package com.azure.resourcemanager.datadog.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.datadog.fluent.models.DatadogSingleSignOnResourceInner;
import com.azure.resourcemanager.datadog.models.DatadogSingleSignOnProperties;
import com.azure.resourcemanager.datadog.models.DatadogSingleSignOnResource;

public final class DatadogSingleSignOnResourceImpl
    implements DatadogSingleSignOnResource, DatadogSingleSignOnResource.Definition, DatadogSingleSignOnResource.Update {
    private DatadogSingleSignOnResourceInner innerObject;

    private final com.azure.resourcemanager.datadog.MicrosoftDatadogManager serviceManager;

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

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

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

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

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.datadog.MicrosoftDatadogManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String monitorName;

    private String configurationName;

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

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

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

    DatadogSingleSignOnResourceImpl(
        String name, com.azure.resourcemanager.datadog.MicrosoftDatadogManager serviceManager) {
        this.innerObject = new DatadogSingleSignOnResourceInner();
        this.serviceManager = serviceManager;
        this.configurationName = name;
    }

    public DatadogSingleSignOnResourceImpl update() {
        return this;
    }

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

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

    DatadogSingleSignOnResourceImpl(
        DatadogSingleSignOnResourceInner innerObject,
        com.azure.resourcemanager.datadog.MicrosoftDatadogManager 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 DatadogSingleSignOnResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSingleSignOnConfigurations()
                .getWithResponse(resourceGroupName, monitorName, configurationName, Context.NONE)
                .getValue();
        return this;
    }

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

    public DatadogSingleSignOnResourceImpl withProperties(DatadogSingleSignOnProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
