using System;
using System.Runtime.InteropServices;

namespace NavigationExample
{
    /// <summary>
    /// C# struct layout cho protocol_msgs (robot_protocol_msgs C API).
    /// Khớp với pnkx_nav_core/src/APIs/c_api/include/protocol_msgs/*.h
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct ControlPoint
    {
        public double x;
        public double y;
        public double weight;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct ActionParameter
    {
        public IntPtr key;   // char*
        public IntPtr value; // char*
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct NodePosition
    {
        public double x;
        public double y;
        public double theta;
        public float allowedDeviationXY;
        public float allowedDeviationTheta;
        public IntPtr mapId;          // char*
        public IntPtr mapDescription; // char*
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct Trajectory
    {
        public uint degree;
        public IntPtr knotVector;           // double*
        public UIntPtr knotVector_count;
        public IntPtr controlPoints;        // ControlPoint*
        public UIntPtr controlPoints_count;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct Action
    {
        public IntPtr actionType;       // char*
        public IntPtr actionId;         // char*
        public IntPtr actionDescription;// char*
        public IntPtr blockingType;     // char*
        public IntPtr actionParameters; // ActionParameter*
        public UIntPtr actionParameters_count;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct Node
    {
        public IntPtr nodeId;           // char*
        public int sequenceId;
        public IntPtr nodeDescription;  // char*
        public byte released;
        public NodePosition nodePosition;
        public IntPtr actions;          // Action*
        public UIntPtr actions_count;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct Edge
    {
        public IntPtr edgeId;           // char*
        public int sequenceId;
        public IntPtr edgeDescription; // char*
        public byte released;
        public IntPtr startNodeId;     // char*
        public IntPtr endNodeId;       // char*
        public double maxSpeed;
        public double maxHeight;
        public double minHeight;
        public double orientation;
        public IntPtr orientationType; // char*
        public IntPtr direction;       // char*
        public byte rotationAllowed;
        public double maxRotationSpeed;
        public Trajectory trajectory;
        public double length;
        public IntPtr actions;          // Action*
        public UIntPtr actions_count;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct Order
    {
        public int headerId;
        public IntPtr timestamp;        // char*
        public IntPtr version;         // char*
        public IntPtr manufacturer;    // char*
        public IntPtr serialNumber;    // char*
        public IntPtr orderId;         // char*
        public uint orderUpdateId;
        public IntPtr nodes;           // Node*
        public UIntPtr nodes_count;
        public IntPtr edges;           // Edge*
        public UIntPtr edges_count;
        public IntPtr zoneSetId;      // char*
    }
}
