using TraceCad.Core.Geometry;
using TraceCad.Core.Model;
using TraceCad.Core.Validation;
using Xunit;

namespace TraceCad.Tests;

public sealed class ValidationTests
{
    [Fact]
    public void ValidatorReportsZeroLengthLineAsError()
    {
        var document = SketchDocument.CreateDefault();
        document.AddEntity(new LineEntity(
            Guid.NewGuid(),
            Layer.Cut.Name,
            new Point2(10, 10),
            new Point2(10, 10)));

        var issues = DrawingValidator.Validate(document);

        Assert.Contains(issues, issue =>
            issue.Severity == DrawingIssueSeverity.Error &&
            issue.Code == "line.zero_length");
    }

    [Fact]
    public void ValidatorReportsTinyLineAsWarning()
    {
        var document = SketchDocument.CreateDefault();
        document.AddEntity(new LineEntity(
            Guid.NewGuid(),
            Layer.Cut.Name,
            new Point2(0, 0),
            new Point2(0.01, 0)));

        var issues = DrawingValidator.Validate(document);

        Assert.Contains(issues, issue =>
            issue.Severity == DrawingIssueSeverity.Warning &&
            issue.Code == "line.tiny");
    }

    [Fact]
    public void ValidatorIgnoresOpenEndpointsOnNonExportableLayers()
    {
        var document = SketchDocument.CreateDefault();
        document.AddEntity(new LineEntity(
            Guid.NewGuid(),
            Layer.Construction.Name,
            new Point2(0, 0),
            new Point2(100, 0)));

        var issues = DrawingValidator.Validate(document);

        Assert.DoesNotContain(issues, issue => issue.Code == "contour.open_endpoint");
    }
}
