using TraceCad.Core.Geometry;

namespace TraceCad.Vision.Calibration;

public sealed record ReferenceSheetTemplate(
    string Id,
    double WidthMm,
    double HeightMm,
    double MarkerSizeMm,
    double ReferenceLineLengthMm,
    Point2 CrosshairMm,
    IReadOnlyList<ReferenceMarkerDefinition> Markers)
{
    public Point2 ReferenceLineStartMm =>
        new(CrosshairMm.X - (ReferenceLineLengthMm / 2.0), CrosshairMm.Y);

    public Point2 ReferenceLineEndMm =>
        new(CrosshairMm.X + (ReferenceLineLengthMm / 2.0), CrosshairMm.Y);

    public static ReferenceSheetTemplate DefaultA4()
    {
        const double width = 297.0;
        const double height = 210.0;
        const double marker = 15.0;

        return new ReferenceSheetTemplate(
            "easytrace-a4-aruco-5x5-v1",
            width,
            height,
            marker,
            ReferenceLineLengthMm: 30.0,
            CrosshairMm: new Point2(width / 2.0, height / 2.0),
            Markers: new[]
            {
                new ReferenceMarkerDefinition(0, new Point2(29.804, 10.666), marker),
                new ReferenceMarkerDefinition(1, new Point2(104.776, 10.666), marker),
                new ReferenceMarkerDefinition(2, new Point2(176.221, 10.666), marker),
                new ReferenceMarkerDefinition(3, new Point2(251.193, 10.666), marker),
                new ReferenceMarkerDefinition(4, new Point2(29.804, 184.417), marker),
                new ReferenceMarkerDefinition(5, new Point2(104.933, 184.417), marker),
                new ReferenceMarkerDefinition(6, new Point2(176.221, 184.417), marker),
                new ReferenceMarkerDefinition(7, new Point2(251.193, 184.417), marker)
            });
    }
}
