using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Scripts;

namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Types;

/// <summary>
/// Commons-010: coverage for the small computed-property logic on
/// <see cref="ConfigurationDiff"/> and <see cref="ScriptScope"/>.
/// </summary>
public class FlatteningAndScriptScopeTests
{
    [Fact]
    public void ConfigurationDiff_NoChanges_HasChangesIsFalse()
    {
        var diff = new ConfigurationDiff { InstanceUniqueName = "inst-1" };

        Assert.False(diff.HasChanges);
    }

    [Fact]
    public void ConfigurationDiff_WithAttributeChange_HasChangesIsTrue()
    {
        var diff = new ConfigurationDiff
        {
            InstanceUniqueName = "inst-1",
            AlarmChanges = new[]
            {
                new DiffEntry<ResolvedAlarm> { CanonicalName = "HiAlarm", ChangeType = DiffChangeType.Added }
            }
        };

        Assert.True(diff.HasChanges);
    }

    [Fact]
    public void ScriptScope_Root_HasNoParent()
    {
        Assert.False(ScriptScope.Root.HasParent);
        Assert.Null(ScriptScope.Root.ParentPath);
    }

    [Fact]
    public void ScriptScope_WithParentPath_HasParentIsTrue()
    {
        var scope = new ScriptScope("Pump1.Motor", "Pump1");

        Assert.True(scope.HasParent);
        Assert.Equal("Pump1", scope.ParentPath);
    }
}
