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

package com.azure.resourcemanager.securityinsights.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.securityinsights.fluent.models.SourceControlInner;
import com.azure.resourcemanager.securityinsights.models.ContentType;
import com.azure.resourcemanager.securityinsights.models.DeploymentInfo;
import com.azure.resourcemanager.securityinsights.models.RepoType;
import com.azure.resourcemanager.securityinsights.models.Repository;
import com.azure.resourcemanager.securityinsights.models.RepositoryResourceInfo;
import com.azure.resourcemanager.securityinsights.models.SourceControl;
import com.azure.resourcemanager.securityinsights.models.Version;
import java.util.Collections;
import java.util.List;

public final class SourceControlImpl implements SourceControl, SourceControl.Definition {
    private SourceControlInner innerObject;

    private final com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager;

    SourceControlImpl(
        SourceControlInner innerObject,
        com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

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

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

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

    public Version version() {
        return this.innerModel().version();
    }

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

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

    public RepoType repoType() {
        return this.innerModel().repoType();
    }

    public List<ContentType> contentTypes() {
        List<ContentType> inner = this.innerModel().contentTypes();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public Repository repository() {
        return this.innerModel().repository();
    }

    public RepositoryResourceInfo repositoryResourceInfo() {
        return this.innerModel().repositoryResourceInfo();
    }

    public DeploymentInfo lastDeploymentInfo() {
        return this.innerModel().lastDeploymentInfo();
    }

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

    private com.azure.resourcemanager.securityinsights.SecurityInsightsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String workspaceName;

    private String sourceControlId;

    public SourceControlImpl withExistingWorkspace(String resourceGroupName, String workspaceName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        return this;
    }

    public SourceControl create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSourceControlsOperations()
                .createWithResponse(resourceGroupName, workspaceName, sourceControlId, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public SourceControl create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSourceControlsOperations()
                .createWithResponse(resourceGroupName, workspaceName, sourceControlId, this.innerModel(), context)
                .getValue();
        return this;
    }

    SourceControlImpl(String name, com.azure.resourcemanager.securityinsights.SecurityInsightsManager serviceManager) {
        this.innerObject = new SourceControlInner();
        this.serviceManager = serviceManager;
        this.sourceControlId = name;
    }

    public SourceControl refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSourceControlsOperations()
                .getWithResponse(resourceGroupName, workspaceName, sourceControlId, Context.NONE)
                .getValue();
        return this;
    }

    public SourceControl refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getSourceControlsOperations()
                .getWithResponse(resourceGroupName, workspaceName, sourceControlId, context)
                .getValue();
        return this;
    }

    public SourceControlImpl withEtag(String etag) {
        this.innerModel().withEtag(etag);
        return this;
    }

    public SourceControlImpl withIdPropertiesId(String idPropertiesId) {
        this.innerModel().withIdPropertiesId(idPropertiesId);
        return this;
    }

    public SourceControlImpl withVersion(Version version) {
        this.innerModel().withVersion(version);
        return this;
    }

    public SourceControlImpl withDisplayName(String displayName) {
        this.innerModel().withDisplayName(displayName);
        return this;
    }

    public SourceControlImpl withDescription(String description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public SourceControlImpl withRepoType(RepoType repoType) {
        this.innerModel().withRepoType(repoType);
        return this;
    }

    public SourceControlImpl withContentTypes(List<ContentType> contentTypes) {
        this.innerModel().withContentTypes(contentTypes);
        return this;
    }

    public SourceControlImpl withRepository(Repository repository) {
        this.innerModel().withRepository(repository);
        return this;
    }

    public SourceControlImpl withRepositoryResourceInfo(RepositoryResourceInfo repositoryResourceInfo) {
        this.innerModel().withRepositoryResourceInfo(repositoryResourceInfo);
        return this;
    }

    public SourceControlImpl withLastDeploymentInfo(DeploymentInfo lastDeploymentInfo) {
        this.innerModel().withLastDeploymentInfo(lastDeploymentInfo);
        return this;
    }
}
