using ZB.MOM.WW.ScadaBridge.CLI.Commands;

namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;

/// <summary>
/// #257: <c>--trigger-kind</c> is written into the trigger-config JSON by
/// <see cref="ZB.MOM.WW.ScadaBridge.CLI.TriggerConfigJson.InjectAnalysisKind"/>, which
/// returns null (dropping the kind) when no <c>--trigger-config</c> is supplied. Passing
/// <c>--trigger-kind</c> without <c>--trigger-config</c> was therefore a silent no-op.
/// The CLI now detects that combination (<see cref="TemplateCommands.TriggerKindWillBeIgnored"/>)
/// and warns the user (warn-and-continue, not a hard error). These tests pin the predicate.
/// </summary>
public class TemplateTriggerKindIgnoredTests
{
    [Fact]
    public void KindWithoutConfig_WillBeIgnored()
    {
        Assert.True(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: null, triggerKind: "strict"));
    }

    [Fact]
    public void KindWithBlankConfig_WillBeIgnored()
    {
        Assert.True(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: "  ", triggerKind: "strict"));
    }

    [Fact]
    public void KindWithConfig_NotIgnored()
    {
        Assert.False(TemplateCommands.TriggerKindWillBeIgnored(
            triggerConfig: "{\"expression\":\"x > 0\"}", triggerKind: "strict"));
    }

    [Fact]
    public void NoKind_NotIgnored()
    {
        // No --trigger-kind at all → nothing to warn about, even without a config.
        Assert.False(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: null, triggerKind: null));
        Assert.False(TemplateCommands.TriggerKindWillBeIgnored(triggerConfig: null, triggerKind: "   "));
    }

    [Fact]
    public void NoKindWithConfig_NotIgnored()
    {
        Assert.False(TemplateCommands.TriggerKindWillBeIgnored(
            triggerConfig: "{\"expression\":\"x > 0\"}", triggerKind: null));
    }
}
