using System;
using Autodesk.Navisworks.Api;

namespace NavisworksTransport
{
    /// <summary>
    /// 可序列化的点结构体
    /// </summary>
    [Serializable]
    [System.Xml.Serialization.XmlType("CachedPoint3D")]
    public struct CachedPoint3D
    {
        [System.Xml.Serialization.XmlAttribute("X")]
        public double X { get; set; }
        
        [System.Xml.Serialization.XmlAttribute("Y")]
        public double Y { get; set; }
        
        [System.Xml.Serialization.XmlAttribute("Z")]
        public double Z { get; set; }

        public CachedPoint3D(double x, double y, double z)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public CachedPoint3D(Point3D point)
        {
            X = point.X;
            Y = point.Y;
            Z = point.Z;
        }

        public Point3D ToNavisworksPoint3D()
        {
            return new Point3D(X, Y, Z);
        }

        public override string ToString()
        {
            return $"Point3D({X:F3}, {Y:F3}, {Z:F3})";
        }
    }

    /// <summary>
    /// 可序列化的三角形结构体
    /// </summary>
    [Serializable]
    [System.Xml.Serialization.XmlType("CachedTriangle3D")]
    public struct CachedTriangle3D
    {
        [System.Xml.Serialization.XmlElement("Point1")]
        public CachedPoint3D Point1 { get; set; }
        
        [System.Xml.Serialization.XmlElement("Point2")]
        public CachedPoint3D Point2 { get; set; }
        
        [System.Xml.Serialization.XmlElement("Point3")]
        public CachedPoint3D Point3 { get; set; }

        public CachedTriangle3D(CachedPoint3D point1, CachedPoint3D point2, CachedPoint3D point3)
        {
            Point1 = point1;
            Point2 = point2;
            Point3 = point3;
        }

        public CachedTriangle3D(Point3D point1, Point3D point2, Point3D point3)
        {
            Point1 = new CachedPoint3D(point1);
            Point2 = new CachedPoint3D(point2);
            Point3 = new CachedPoint3D(point3);
        }

        public override string ToString()
        {
            return $"Triangle[{Point1}, {Point2}, {Point3}]";
        }
    }
}