using System.Collections.Immutable;
using NodePipeline.Engine.CodeGeneration.Abstractions;
using NodePipeline.Engine.Tests.CodeGeneratorTests.Fixtures;
using NodePipeline.Engine.Tests.CodeGeneratorTests.Fixtures.MockNodes;

namespace NodePipeline.Engine.Tests.CodeGeneratorTests;

public class NodeModelBuilderTests
{
    private static readonly string SourceDir = Path.Combine(AppContext.BaseDirectory, "..", "..", "..",
        "CodeGeneratorTests", "Fixtures", "MockNodes");

    //node type name short sanitized must not contain "global::"
    [Fact]
    public void ModelContainsNode()
    {
        var fullTypeName = typeof(SimpleNamedNode).FullName!;
        // Arrange
        var symbol = RoslynTestHelpers.GetNamedTypeSymbolFromSource(fullTypeName, SourceDir);

        // Act
        var (model, _) = NodeModelBuilder.Build(ImmutableArray.Create(symbol));

        // Assert
        var node = model.Nodes.FirstOrDefault(n => n.Type == "NamedNode");
        Assert.NotNull(node);
        Assert.Equal("NamedNode", node.Type);
        Assert.True(node.HasParameterlessConstructor);
    }

    [Fact]
    public void ModelContainsNodeWithoutParameterlessConstructor()
    {
        // Arrange
        var fullTypeName = typeof(NodeWithoutParameterlessConstructor).FullName!;
        var symbol = RoslynTestHelpers.GetNamedTypeSymbolFromSource(fullTypeName, SourceDir);

        // Act
        var (model, _) = NodeModelBuilder.Build(ImmutableArray.Create(symbol));

        // Assert
        var node = model.Nodes.FirstOrDefault(n => n.TypeNameShort.Contains("NodeWithoutParameterlessConstructor"));
        Assert.NotNull(node);
        Assert.False(node.HasParameterlessConstructor);
    }


    /*
    [Fact]
    public void ModelNotContainNode()
    {
        // Arrange
        var symbol = RoslynTestHelpers.GetNamedTypeSymbolFromSource(typeof(NotImplementedINode).FullName, _sourceDir);

        // Act
        var model = NodeModelBuilder.Build(ImmutableArray.Create(symbol));

        // Assert
        Assert.Empty(model.Nodes);
    }
    */
}