using TraceCad.Core.Commands;
using TraceCad.Core.Geometry;
using TraceCad.Core.Model;

namespace TraceCad.App.Tools;

public sealed class ToolContext(
    SketchDocument document,
    CommandManager commands,
    Func<Point2, SnapResult> snapPoint,
    Func<Point2, double, Entity?> hitTest,
    Func<Entity?> getSelected,
    Action<Entity?> setSelected,
    Action<string> setStatus,
    Action invalidate,
    bool tangentConstraint)
{
    public SketchDocument Document { get; } = document;

    public CommandManager Commands { get; } = commands;

    public bool TangentConstraint { get; } = tangentConstraint;

    public Point2 Snap(Point2 point) => SnapDetailed(point).Point;

    public SnapResult SnapDetailed(Point2 point) => snapPoint(point);

    public Entity? HitTest(Point2 point, double tolerancePixels) => hitTest(point, tolerancePixels);

    public Entity? SelectedEntity => getSelected();

    public void SetSelected(Entity? entity) => setSelected(entity);

    public void SetStatus(string status) => setStatus(status);

    public void Invalidate() => invalidate();
}
