using System.Collections.Generic;
using Autodesk.Navisworks.Api;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NavisworksTransport.UnitTests.Core
{
    [TestClass]
    public class PathPlanningManagerHoistingCompletionTests
    {
        [TestMethod]
        public void ReuseLastHoistingPointAsDescendPoint_ShouldPreserveGeometryAndAvoidDuplicateSegment_FromRealLogCase()
        {
            var originalLastAerialPointPosition = new Point3D(-132.36, -16.89, -6.95);
            var pathPoints = new List<PathPoint>
            {
                new PathPoint(new Point3D(-140.00, -30.01, -6.95), "起吊点", PathPointType.StartPoint) { Index = 0, Direction = HoistingPointDirection.Vertical },
                new PathPoint(new Point3D(-140.00, -16.89, -6.95), "提升点", PathPointType.WayPoint) { Index = 1, Direction = HoistingPointDirection.Vertical },
                new PathPoint(new Point3D(-150.00, -16.89, -6.95), "路径点7", PathPointType.WayPoint) { Index = 2, Direction = HoistingPointDirection.Longitudinal },
                new PathPoint(originalLastAerialPointPosition, "路径点8", PathPointType.WayPoint) { Index = 3, Direction = HoistingPointDirection.Longitudinal }
            };

            var finalGroundPoint = new Point3D(-132.36, -30.01, -6.95);
            var originalLastPoint = pathPoints[3];

            PathPoint descendPoint = PathPlanningManager.ReuseLastHoistingPointAsDescendPoint(pathPoints);
            var endPoint = new PathPoint(finalGroundPoint, "落地点", PathPointType.EndPoint)
            {
                Index = pathPoints.Count,
                Direction = HoistingPointDirection.Vertical
            };
            pathPoints.Add(endPoint);

            Assert.AreEqual(5, pathPoints.Count);
            Assert.AreSame(pathPoints[3], descendPoint);
            Assert.AreSame(originalLastPoint, descendPoint);
            Assert.AreEqual("下降点", pathPoints[3].Name);
            Assert.AreEqual(PathPointType.WayPoint, pathPoints[3].Type);
            Assert.AreEqual(HoistingPointDirection.Vertical, pathPoints[3].Direction);
            Assert.AreSame(originalLastAerialPointPosition, pathPoints[3].Position);

            Assert.AreEqual("落地点", pathPoints[4].Name);
            Assert.AreEqual(PathPointType.EndPoint, pathPoints[4].Type);
            Assert.AreEqual(HoistingPointDirection.Vertical, pathPoints[4].Direction);
            Assert.AreSame(finalGroundPoint, pathPoints[4].Position);
        }
    }
}
