using System;
using System.Windows.Media.Media3D;
using System.Collections.Generic;
using System.Linq;
using devDept.Eyeshot;
using devDept.Eyeshot.Control;
using devDept.Eyeshot.Entities;
using devDept.Geometry;
using WpfEngineeringSketch.Models.Scene;

namespace WpfEngineeringSketch.Tools3D
{
    public static class SnappingHelper
    {
        public static System.Windows.Media.Media3D.Point3D Snap(System.Windows.Media.Media3D.Point3D point, double gridSize)
        {
            double x = System.Math.Round(point.X / gridSize) * gridSize;
            double y = System.Math.Round(point.Y / gridSize) * gridSize;
            double z = System.Math.Round(point.Z / gridSize) * gridSize;
            return new System.Windows.Media.Media3D.Point3D(x, y, z);
        }

        public static System.Windows.Media.Media3D.Point3D? FindClosestSnapPoint(Design design, System.Windows.Point mousePos, double snapDistance) {
            var point = new System.Drawing.Point((int)mousePos.X, (int)mousePos.Y);
            design.ScreenToPlane(point, Plane.XY, out devDept.Geometry.Point3D world);
            return new System.Windows.Media.Media3D.Point3D(world.X, world.Y, world.Z);
        }

                public static System.Windows.Media.Media3D.Point3D? FindNearestIntersection(System.Windows.Media.Media3D.Point3D point, System.Collections.ObjectModel.ObservableCollection<SceneObject> objects)
        {
            var gridLines = objects.Where(o => o.Type == BlockType.GridLine).ToList();
            if (gridLines.Count < 2) return null;
            return null;
        }
    }
}
