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

package com.azure.resourcemanager.security.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.security.fluent.models.ConnectorSettingInner;
import com.azure.resourcemanager.security.models.AuthenticationDetailsProperties;
import com.azure.resourcemanager.security.models.ConnectorSetting;
import com.azure.resourcemanager.security.models.HybridComputeSettingsProperties;

public final class ConnectorSettingImpl
    implements ConnectorSetting, ConnectorSetting.Definition, ConnectorSetting.Update {
    private ConnectorSettingInner innerObject;

    private final com.azure.resourcemanager.security.SecurityManager serviceManager;

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

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

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

    public HybridComputeSettingsProperties hybridComputeSettings() {
        return this.innerModel().hybridComputeSettings();
    }

    public AuthenticationDetailsProperties authenticationDetails() {
        return this.innerModel().authenticationDetails();
    }

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

    private com.azure.resourcemanager.security.SecurityManager manager() {
        return this.serviceManager;
    }

    private String connectorName;

    public ConnectorSetting create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdateWithResponse(connectorName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public ConnectorSetting create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdateWithResponse(connectorName, this.innerModel(), context)
                .getValue();
        return this;
    }

    ConnectorSettingImpl(String name, com.azure.resourcemanager.security.SecurityManager serviceManager) {
        this.innerObject = new ConnectorSettingInner();
        this.serviceManager = serviceManager;
        this.connectorName = name;
    }

    public ConnectorSettingImpl update() {
        return this;
    }

    public ConnectorSetting apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdateWithResponse(connectorName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public ConnectorSetting apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getConnectors()
                .createOrUpdateWithResponse(connectorName, this.innerModel(), context)
                .getValue();
        return this;
    }

    ConnectorSettingImpl(
        ConnectorSettingInner innerObject, com.azure.resourcemanager.security.SecurityManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.connectorName = Utils.getValueFromIdByName(innerObject.id(), "connectors");
    }

    public ConnectorSetting refresh() {
        this.innerObject =
            serviceManager.serviceClient().getConnectors().getWithResponse(connectorName, Context.NONE).getValue();
        return this;
    }

    public ConnectorSetting refresh(Context context) {
        this.innerObject =
            serviceManager.serviceClient().getConnectors().getWithResponse(connectorName, context).getValue();
        return this;
    }

    public ConnectorSettingImpl withHybridComputeSettings(HybridComputeSettingsProperties hybridComputeSettings) {
        this.innerModel().withHybridComputeSettings(hybridComputeSettings);
        return this;
    }

    public ConnectorSettingImpl withAuthenticationDetails(AuthenticationDetailsProperties authenticationDetails) {
        this.innerModel().withAuthenticationDetails(authenticationDetails);
        return this;
    }
}
