using ClaudeDo.Installer.Checks;
using ClaudeDo.Installer.Core;

namespace ClaudeDo.Installer.Tests.Pages.SystemCheckPage;

internal sealed class FakeEnvironmentCheck : IEnvironmentCheck
{
    private readonly Func<InstallContext, CancellationToken, Task<CheckResult>> _run;

    public FakeEnvironmentCheck(string id, CheckSeverity severity, Func<InstallContext, CancellationToken, Task<CheckResult>> run)
    {
        Id = id;
        Severity = severity;
        _run = run;
    }

    public static FakeEnvironmentCheck Ok(string id, CheckSeverity severity = CheckSeverity.Error) =>
        new(id, severity, (_, _) => Task.FromResult(CheckResult.Ok(id, severity, $"checks.{id}.title", "ok")));

    public static FakeEnvironmentCheck Fail(string id, CheckSeverity severity) =>
        new(id, severity, (_, _) => Task.FromResult(CheckResult.Fail(id, severity, $"checks.{id}.title", "failed")));

    public static FakeEnvironmentCheck Unknown(string id, CheckSeverity severity = CheckSeverity.Warning) =>
        new(id, severity, (_, _) => Task.FromResult(CheckResult.Unknown(id, severity, $"checks.{id}.title", "unknown")));

    public string Id { get; }
    public CheckSeverity Severity { get; }
    public int CallCount { get; private set; }

    public Task<CheckResult> RunAsync(InstallContext ctx, CancellationToken ct)
    {
        CallCount++;
        return _run(ctx, ct);
    }
}
