// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Platform.Logging;

using Moq;

namespace Microsoft.Testing.Platform.UnitTests;

internal static class LogTestHelpers
{
    public static IEnumerable<LogLevel> GetLogLevels()
#if NET
        => Enum.GetValues<LogLevel>();
#else
        => typeof(LogLevel).GetEnumValues().Cast<LogLevel>();
#endif

    public static IEnumerable<object[]> GetLogLevelsForDynamicData()
        => GetLogLevels().Select(x => new object[] { x });

    public static IEnumerable<(LogLevel DefaultLevel, LogLevel CurrentLevel)> GetLogLevelCombinations()
    {
        List<(LogLevel, LogLevel)> logLevelCombinations = [];
        LogLevel[] logLevels = [.. GetLogLevels()];

        for (int i = 0; i < logLevels.Length; i++)
        {
            for (int j = 0; j < logLevels.Length; j++)
            {
                logLevelCombinations.Add((logLevels[i], logLevels[j]));
            }
        }

        return logLevelCombinations;
    }

    public static Times GetExpectedLogCallTimes(LogLevel defaultLevel, LogLevel currentLevel)
        => IsLogEnabled(defaultLevel, currentLevel) ? Times.Once() : Times.Never();

    public static bool IsLogEnabled(LogLevel defaultLevel, LogLevel currentLevel)
        => currentLevel >= defaultLevel;
}
