internal static partial class Program
{
    static async Task TestEntryAiHealthDefaultAsync()
    {
        var entry = NewEntry();
        var response = await entry.HandleCommandAsync("""{"action":"ai.health"}""");
        using var doc = JsonDocument.Parse(response);

        Assert(doc.RootElement.GetProperty("ok").GetBoolean(), "Expected ok=true for ai.health.");
        var data = doc.RootElement.GetProperty("data");
        Assert(data.GetProperty("Enabled").GetBoolean() is false, "Expected AI disabled by default.");
        Assert(string.Equals(data.GetProperty("Provider").GetString(), "none", StringComparison.OrdinalIgnoreCase), "Expected default provider 'none'.");
    }

    static async Task TestEntryAiSummarizeEntryDisabledAsync()
    {
        var entry = NewEntry();
        var request = JsonSerializer.Serialize(new
        {
            action = "ai.summarize_entry",
            payload = new
            {
                content = "sample entry"
            }
        });

        var response = await entry.HandleCommandAsync(request);
        using var doc = JsonDocument.Parse(response);

        Assert(doc.RootElement.GetProperty("ok").GetBoolean(), "Expected ok=true for disabled ai.summarize_entry.");
        var data = doc.RootElement.GetProperty("data").GetString() ?? "";
        Assert(data.Contains("disabled", StringComparison.OrdinalIgnoreCase), "Expected disabled provider message for ai.summarize_entry.");
    }

    static async Task TestEntryAiSummarizeAllDisabledAsync()
    {
        var entry = NewEntry();
        var request = JsonSerializer.Serialize(new
        {
            action = "ai.summarize_all",
            payload = new
            {
                entries = new[] { "entry one", "entry two" }
            }
        });

        var response = await entry.HandleCommandAsync(request);
        using var doc = JsonDocument.Parse(response);

        Assert(doc.RootElement.GetProperty("ok").GetBoolean(), "Expected ok=true for disabled ai.summarize_all.");
        var data = doc.RootElement.GetProperty("data").GetString() ?? "";
        Assert(data.Contains("disabled", StringComparison.OrdinalIgnoreCase), "Expected disabled provider message for ai.summarize_all.");
    }

    static async Task TestEntryAiChatDisabledAsync()
    {
        var entry = NewEntry();
        var request = JsonSerializer.Serialize(new
        {
            action = "ai.chat",
            payload = new
            {
                prompt = "hello cloud"
            }
        });

        var response = await entry.HandleCommandAsync(request);
        using var doc = JsonDocument.Parse(response);

        Assert(doc.RootElement.GetProperty("ok").GetBoolean(), "Expected ok=true for disabled ai.chat.");
        var data = doc.RootElement.GetProperty("data").GetString() ?? "";
        Assert(data.Contains("disabled", StringComparison.OrdinalIgnoreCase), "Expected disabled provider message for ai.chat.");
    }

    static async Task TestEntryAiEmbedDisabledAsync()
    {
        var entry = NewEntry();
        var request = JsonSerializer.Serialize(new
        {
            action = "ai.embed",
            payload = new
            {
                content = "embedding source text"
            }
        });

        var response = await entry.HandleCommandAsync(request);
        using var doc = JsonDocument.Parse(response);

        Assert(doc.RootElement.GetProperty("ok").GetBoolean(), "Expected ok=true for disabled ai.embed.");
        var data = doc.RootElement.GetProperty("data");
        Assert(data.ValueKind == JsonValueKind.Array, "Expected ai.embed response to be a JSON array.");
        Assert(data.GetArrayLength() == 0, "Expected disabled ai.embed to return an empty vector.");
    }

    static async Task TestEntrySpeechDevicesListDisabledAsync()
    {
        var entry = NewEntry();
        var request = JsonSerializer.Serialize(new
        {
            action = "speech.devices.list",
            payload = new { }
        });

        var response = await entry.HandleCommandAsync(request);
        using var doc = JsonDocument.Parse(response);
        Assert(doc.RootElement.GetProperty("ok").GetBoolean(), "Expected ok=true for speech.devices.list when disabled.");
        var data = doc.RootElement.GetProperty("data");
        Assert(data.ValueKind == JsonValueKind.Object, "Expected speech.devices.list data to be an object.");
    }

    static async Task TestEntrySpeechTranscribeDisabledAsync()
    {
        var entry = NewEntry();
        var request = JsonSerializer.Serialize(new
        {
            action = "speech.transcribe",
            payload = new
            {
                text = "fixture transcript",
                engine = "whisper"
            }
        });

        var response = await entry.HandleCommandAsync(request);
        using var doc = JsonDocument.Parse(response);
        Assert(doc.RootElement.GetProperty("ok").GetBoolean(), "Expected ok=true for speech.transcribe when disabled.");
        var data = doc.RootElement.GetProperty("data");
        Assert(data.ValueKind == JsonValueKind.Object, "Expected speech.transcribe data to be an object.");
        var warning = data.TryGetProperty("Warning", out var warningNode) ? warningNode.GetString() ?? "" : "";
        Assert(warning.Contains("disabled", StringComparison.OrdinalIgnoreCase), "Expected disabled speech warning.");
    }
}

