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

package com.azure.resourcemanager.securitydevops.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.securitydevops.fluent.models.AzureDevOpsOrgInner;
import com.azure.resourcemanager.securitydevops.models.AzureDevOpsOrg;
import com.azure.resourcemanager.securitydevops.models.AzureDevOpsOrgProperties;

public final class AzureDevOpsOrgImpl implements AzureDevOpsOrg, AzureDevOpsOrg.Definition, AzureDevOpsOrg.Update {
    private AzureDevOpsOrgInner innerObject;

    private final com.azure.resourcemanager.securitydevops.SecurityDevOpsManager serviceManager;

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.securitydevops.SecurityDevOpsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String azureDevOpsConnectorName;

    private String azureDevOpsOrgName;

    public AzureDevOpsOrgImpl withExistingAzureDevOpsConnector(
        String resourceGroupName, String azureDevOpsConnectorName) {
        this.resourceGroupName = resourceGroupName;
        this.azureDevOpsConnectorName = azureDevOpsConnectorName;
        return this;
    }

    public AzureDevOpsOrg create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAzureDevOpsOrgs()
                .createOrUpdate(
                    resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, this.innerModel(), Context.NONE);
        return this;
    }

    public AzureDevOpsOrg create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAzureDevOpsOrgs()
                .createOrUpdate(
                    resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, this.innerModel(), context);
        return this;
    }

    AzureDevOpsOrgImpl(String name, com.azure.resourcemanager.securitydevops.SecurityDevOpsManager serviceManager) {
        this.innerObject = new AzureDevOpsOrgInner();
        this.serviceManager = serviceManager;
        this.azureDevOpsOrgName = name;
    }

    public AzureDevOpsOrgImpl update() {
        return this;
    }

    public AzureDevOpsOrg apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAzureDevOpsOrgs()
                .update(
                    resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, this.innerModel(), Context.NONE);
        return this;
    }

    public AzureDevOpsOrg apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAzureDevOpsOrgs()
                .update(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, this.innerModel(), context);
        return this;
    }

    AzureDevOpsOrgImpl(
        AzureDevOpsOrgInner innerObject,
        com.azure.resourcemanager.securitydevops.SecurityDevOpsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.azureDevOpsConnectorName = Utils.getValueFromIdByName(innerObject.id(), "azureDevOpsConnectors");
        this.azureDevOpsOrgName = Utils.getValueFromIdByName(innerObject.id(), "orgs");
    }

    public AzureDevOpsOrg refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAzureDevOpsOrgs()
                .getWithResponse(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, Context.NONE)
                .getValue();
        return this;
    }

    public AzureDevOpsOrg refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAzureDevOpsOrgs()
                .getWithResponse(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, context)
                .getValue();
        return this;
    }

    public AzureDevOpsOrgImpl withProperties(AzureDevOpsOrgProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
