// 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.GitHubOwnerInner;
import com.azure.resourcemanager.securitydevops.models.GitHubOwner;
import com.azure.resourcemanager.securitydevops.models.GitHubOwnerProperties;

public final class GitHubOwnerImpl implements GitHubOwner, GitHubOwner.Definition, GitHubOwner.Update {
    private GitHubOwnerInner 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 GitHubOwnerProperties properties() {
        return this.innerModel().properties();
    }

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String gitHubConnectorName;

    private String gitHubOwnerName;

    public GitHubOwnerImpl withExistingGitHubConnector(String resourceGroupName, String gitHubConnectorName) {
        this.resourceGroupName = resourceGroupName;
        this.gitHubConnectorName = gitHubConnectorName;
        return this;
    }

    public GitHubOwner create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGitHubOwners()
                .createOrUpdate(
                    resourceGroupName, gitHubConnectorName, gitHubOwnerName, this.innerModel(), Context.NONE);
        return this;
    }

    public GitHubOwner create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGitHubOwners()
                .createOrUpdate(resourceGroupName, gitHubConnectorName, gitHubOwnerName, this.innerModel(), context);
        return this;
    }

    GitHubOwnerImpl(String name, com.azure.resourcemanager.securitydevops.SecurityDevOpsManager serviceManager) {
        this.innerObject = new GitHubOwnerInner();
        this.serviceManager = serviceManager;
        this.gitHubOwnerName = name;
    }

    public GitHubOwnerImpl update() {
        return this;
    }

    public GitHubOwner apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGitHubOwners()
                .update(resourceGroupName, gitHubConnectorName, gitHubOwnerName, this.innerModel(), Context.NONE);
        return this;
    }

    public GitHubOwner apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGitHubOwners()
                .update(resourceGroupName, gitHubConnectorName, gitHubOwnerName, this.innerModel(), context);
        return this;
    }

    GitHubOwnerImpl(
        GitHubOwnerInner innerObject, com.azure.resourcemanager.securitydevops.SecurityDevOpsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.gitHubConnectorName = Utils.getValueFromIdByName(innerObject.id(), "gitHubConnectors");
        this.gitHubOwnerName = Utils.getValueFromIdByName(innerObject.id(), "owners");
    }

    public GitHubOwner refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGitHubOwners()
                .getWithResponse(resourceGroupName, gitHubConnectorName, gitHubOwnerName, Context.NONE)
                .getValue();
        return this;
    }

    public GitHubOwner refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getGitHubOwners()
                .getWithResponse(resourceGroupName, gitHubConnectorName, gitHubOwnerName, context)
                .getValue();
        return this;
    }

    public GitHubOwnerImpl withProperties(GitHubOwnerProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
