// 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.AzureDevOpsProjectInner;
import com.azure.resourcemanager.securitydevops.models.AzureDevOpsProject;
import com.azure.resourcemanager.securitydevops.models.AzureDevOpsProjectProperties;

public final class AzureDevOpsProjectImpl
    implements AzureDevOpsProject, AzureDevOpsProject.Definition, AzureDevOpsProject.Update {
    private AzureDevOpsProjectInner 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 AzureDevOpsProjectProperties properties() {
        return this.innerModel().properties();
    }

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String azureDevOpsConnectorName;

    private String azureDevOpsOrgName;

    private String azureDevOpsProjectName;

    public AzureDevOpsProjectImpl withExistingOrg(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        this.resourceGroupName = resourceGroupName;
        this.azureDevOpsConnectorName = azureDevOpsConnectorName;
        this.azureDevOpsOrgName = azureDevOpsOrgName;
        return this;
    }

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

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

    AzureDevOpsProjectImpl(String name, com.azure.resourcemanager.securitydevops.SecurityDevOpsManager serviceManager) {
        this.innerObject = new AzureDevOpsProjectInner();
        this.serviceManager = serviceManager;
        this.azureDevOpsProjectName = name;
    }

    public AzureDevOpsProjectImpl update() {
        return this;
    }

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

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

    AzureDevOpsProjectImpl(
        AzureDevOpsProjectInner 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");
        this.azureDevOpsProjectName = Utils.getValueFromIdByName(innerObject.id(), "projects");
    }

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

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

    public AzureDevOpsProjectImpl withProperties(AzureDevOpsProjectProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
