using NexusShell.Services;
using Xunit;

namespace NexusShell.Tests;

public sealed class AppManifestTests
{
    [Fact]
    public void App_hub_manifest_uses_nexus_actions_and_status_labels()
    {
        var catalog = new AppCatalogService();
        catalog.Load();

        Assert.NotEmpty(catalog.Apps);
        Assert.DoesNotContain(catalog.Apps, app =>
            app.ExecutablePath.Contains("explorer.exe", StringComparison.OrdinalIgnoreCase)
            || app.ExecutablePath.Contains("notepad.exe", StringComparison.OrdinalIgnoreCase)
            || app.ExecutablePath.Contains("powershell.exe", StringComparison.OrdinalIgnoreCase));
        Assert.All(catalog.Apps, app => Assert.False(string.IsNullOrWhiteSpace(app.Status)));
        Assert.Contains(catalog.Apps, app =>
            app.ExecutablePath.Equals("nexus:placeholder", StringComparison.OrdinalIgnoreCase)
            && app.Status.Equals("Kommer snart", StringComparison.OrdinalIgnoreCase));
    }

    [Theory]
    [InlineData("app-hub", "nexus:hub")]
    [InlineData("app-settings", "nexus:settings")]
    [InlineData("app-documents", "nexus:files")]
    [InlineData("app-nexus-browser", "nexus:browser")]
    [InlineData("app-calc", "nexus:calculator")]
    [InlineData("app-ninja-store", "nexus:store")]
    public void Core_apps_use_nexus_hosted_routes(string appId, string route)
    {
        var catalog = new AppCatalogService();
        catalog.Load();

        var app = Assert.Single(catalog.Apps, a => a.Id == appId);
        Assert.Equal(route, app.ExecutablePath);
        Assert.NotEqual("nexus:placeholder", app.ExecutablePath, StringComparer.OrdinalIgnoreCase);
    }

    [Fact]
    public void Unfinished_apps_are_explicit_placeholders_not_empty_windows()
    {
        var catalog = new AppCatalogService();
        catalog.Load();

        var notes = Assert.Single(catalog.Apps, a => a.Id == "app-notes");
        Assert.Equal("nexus:placeholder", notes.ExecutablePath);
        Assert.False(string.IsNullOrWhiteSpace(notes.Description));
        Assert.False(string.IsNullOrWhiteSpace(notes.IconPath));
        Assert.Equal("Kommer snart", notes.Status);
    }
}
