// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// --------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.IO;
using Microsoft.Oryx.BuildScriptGenerator.Common;
using Microsoft.Oryx.BuildScriptGeneratorCli;
using Microsoft.Oryx.Tests.Common;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Oryx.BuildImage.Tests
{
    public class NodeJsMonorepoSampleAppsTest : SampleAppsTestBase
    {
        public NodeJsMonorepoSampleAppsTest(ITestOutputHelper output) : base(output)
        {
        }
        private DockerVolume CreateSampleAppVolume(string sampleAppName) =>
            DockerVolume.CreateMirror(Path.Combine(_hostSamplesDir, "nodejs", sampleAppName));

        // [Fact, Trait("category", "githubactions")]
        // public void GeneratesScript_AndBuildMonorepoAppUsingLerna_Npm()
        // {
        //     // Arrange
        //     var appName = "monorepo-lerna-npm";
        //     var volume = CreateSampleAppVolume(appName);
        //     var appDir = volume.ContainerDir;
        //     var appOutputDir = "/tmp/app1-output";
        //     var script = new ShellScriptBuilder()
        //         .SetEnvironmentVariable(
        //             SettingsKeys.EnableNodeMonorepoBuild,
        //             true.ToString())
        //         .AddBuildCommand($"{appDir} -o {appOutputDir}")
        //         .ToString();

        //     // Act
        //     var result = _dockerCli.Run(new DockerRunArguments
        //     {
        //         ImageId = _imageHelper.GetGitHubActionsBuildImage(ImageTestHelperConstants.GitHubActionsBookworm),
        //         EnvironmentVariables = new List<EnvironmentVariable> { CreateAppNameEnvVar(appName) },
        //         Volumes = new List<DockerVolume> { volume },
        //         CommandToExecuteOnRun = "/bin/bash",
        //         CommandArguments = new[] { "-c", script }
        //     });

        //     // Assert
        //     RunAsserts(
        //         () =>
        //         {
        //             Assert.True(result.IsSuccess);
        //         },
        //         result.GetDebugInfo());
        // }


        // This test is failing because for github actions the command manifest file is deleted. This command manifest file is preserved only for vso-focal and vso-debian-bullseye images.(check NodeBashBuildSnippet.sh.tpl line 235 to 250)

        // [Theory, Trait("category", "githubactions")]
        // [InlineData("monorepo-lerna-npm", true)]
        // [InlineData("monorepo-lerna-yarn", true)]
        // [InlineData("linxnodeexpress", false)]
        // public void BuildMonorepoApp_Prints_BuildCommands_In_File(string appName, bool isMonoRepo)
        // {
        //     // Arrange
        //     var volume = CreateSampleAppVolume(appName);
        //     var appDir = volume.ContainerDir;
        //     var appOutputDir = "/tmp/app1-output";
        //     var commandListFile = $"{appOutputDir}/{FilePaths.BuildCommandsFileName}";
        //     var script = new ShellScriptBuilder()
        //         .SetEnvironmentVariable(
        //             SettingsKeys.EnableNodeMonorepoBuild,
        //             isMonoRepo.ToString())
        //         .AddBuildCommand($"{appDir} -o {appOutputDir}")
        //         .AddFileExistsCheck($"{commandListFile}")
        //         .AddStringExistsInFileCheck("PlatformWithVersion=", $"{commandListFile}")
        //         .AddStringExistsInFileCheck("BuildCommands=", $"{commandListFile}")
        //         .ToString();

        //     // Act
        //     var result = _dockerCli.Run(new DockerRunArguments
        //     {
        //         ImageId = _imageHelper.GetGitHubActionsBuildImage(),
        //         EnvironmentVariables = new List<EnvironmentVariable> { CreateAppNameEnvVar(appName) },
        //         Volumes = new List<DockerVolume> { volume },
        //         CommandToExecuteOnRun = "/bin/bash",
        //         CommandArguments = new[] { "-c", script }
        //     });

        //     // Assert
        //     RunAsserts(
        //         () =>
        //         {
        //             Assert.True(result.IsSuccess);
        //         },
        //         result.GetDebugInfo());
        // }

        // [Fact, Trait("category", "githubactions")]
        // public void GeneratesScript_AndBuildMonorepoAppUsingLerna_Yarn()
        // {
        //     // Arrange
        //     var appName = "monorepo-lerna-yarn";
        //     var volume = CreateSampleAppVolume(appName);
        //     var appDir = volume.ContainerDir;
        //     var appOutputDir = "/tmp/app2-output";
        //     var script = new ShellScriptBuilder()
        //         .SetEnvironmentVariable(
        //             SettingsKeys.EnableNodeMonorepoBuild,
        //             true.ToString())
        //         .AddBuildCommand($"{appDir} -o {appOutputDir}")
        //         .AddDirectoryExistsCheck($"{appOutputDir}/node_modules/@babel")
        //         .AddDirectoryExistsCheck($"{appOutputDir}/node_modules/universalify")
        //         .ToString();

        //     // Act
        //     var result = _dockerCli.Run(new DockerRunArguments
        //     {
        //         ImageId = _imageHelper.GetGitHubActionsBuildImage(ImageTestHelperConstants.GitHubActionsBookworm),
        //         EnvironmentVariables = new List<EnvironmentVariable> { CreateAppNameEnvVar(appName) },
        //         Volumes = new List<DockerVolume> { volume },
        //         CommandToExecuteOnRun = "/bin/bash",
        //         CommandArguments = new[] { "-c", script }
        //     });

        //     // Assert
        //     RunAsserts(
        //         () =>
        //         {
        //             Assert.True(result.IsSuccess);
        //         },
        //         result.GetDebugInfo());
        // }
    }
}