using Autodesk.Navisworks.Api;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NavisworksTransport.UnitTests.Core
{
    [TestClass]
    public class PathRouteCloneTests
    {
        [TestMethod]
        public void Clone_ShouldPreserveRailSpecificPropertiesAndGenerateNewIds()
        {
            var route = new PathRoute("原路径")
            {
                PathType = PathType.Rail,
                RailMountMode = RailMountMode.OverRail,
                RailPathDefinitionMode = RailPathDefinitionMode.RailCenterLine,
                RailNormalOffset = 12.5,
                RailPreferredNormal = new Point3D(0, 1, 0)
            };

            route.Points.Add(new PathPoint(new Point3D(1, 2, 3), "起点", PathPointType.StartPoint));
            route.Points.Add(new PathPoint(new Point3D(4, 5, 6), "终点", PathPointType.EndPoint));

            var clonedRoute = route.Clone();

            Assert.AreEqual(PathType.Rail, clonedRoute.PathType);
            Assert.AreEqual(RailMountMode.OverRail, clonedRoute.RailMountMode);
            Assert.AreEqual(RailPathDefinitionMode.RailCenterLine, clonedRoute.RailPathDefinitionMode);
            Assert.AreEqual(12.5, clonedRoute.RailNormalOffset, 1e-6);
            Assert.IsNotNull(clonedRoute.RailPreferredNormal);
            Assert.AreNotEqual(route.Id, clonedRoute.Id);
            Assert.AreEqual(2, clonedRoute.Points.Count);
            Assert.AreNotEqual(route.Points[0].Id, clonedRoute.Points[0].Id);
            Assert.AreEqual(route.Points[0].Name, clonedRoute.Points[0].Name);
            Assert.AreEqual(route.Points[0].Type, clonedRoute.Points[0].Type);
        }

        [TestMethod]
        public void Clone_ShouldCopyGroundEdgesAndRemapPointReferences()
        {
            var route = new PathRoute("地面路径")
            {
                PathType = PathType.Ground,
                TurnRadius = 3.0,
                IsCurved = true
            };

            var startPoint = new PathPoint(new Point3D(0, 0, 0), "起点", PathPointType.StartPoint);
            var endPoint = new PathPoint(new Point3D(10, 0, 0), "终点", PathPointType.EndPoint);
            route.Points.Add(startPoint);
            route.Points.Add(endPoint);
            route.Edges.Add(new PathEdge
            {
                StartPointId = startPoint.Id,
                EndPointId = endPoint.Id,
                SegmentType = PathSegmentType.Straight,
                PhysicalLength = 10.0
            });

            var clonedRoute = route.Clone();

            Assert.AreEqual(PathType.Ground, clonedRoute.PathType);
            Assert.AreEqual(1, clonedRoute.Edges.Count);
            Assert.AreEqual(3.0, clonedRoute.TurnRadius, 1e-6);
            Assert.IsTrue(clonedRoute.IsCurved);
            Assert.AreEqual(clonedRoute.Points[0].Id, clonedRoute.Edges[0].StartPointId);
            Assert.AreEqual(clonedRoute.Points[1].Id, clonedRoute.Edges[0].EndPointId);
            Assert.AreNotEqual(route.Edges[0].Id, clonedRoute.Edges[0].Id);
        }
    }
}
