#pragma once
#include "define.h"

#include <maya/MFnDagNode.h>
#include <maya/MFnMesh.h>
#include <maya/MDagPath.h>
#include <maya/MFnPluginData.h>
#include <maya/MPxData.h>
#include <maya/MTime.h>
#include <maya/MSelectionList.h>
#include <maya/MGlobal.h>
#include <maya/MPlug.h>
#include <maya/MPointArray.h>
#include <maya/MFloatVector.h>
#include <maya/MMeshIntersector.h>
#include <maya/MItDependencyGraph.h>

#if MAYA_APP_VERSION < 2020
#include <XGen/SgCurve.h>
#include <XGen/XgSplineAPI.h>
#else
#include <xgen/src/sggeom/SgCurve.h>
#include <xgen/src/xgsculptcore/api/XgSplineAPI.h>
#endif

#include <sstream>
#include <string>
#include <vector>
#include <map>
#define XGEN_SPLINE_VERSION_2017_UPDATE3 201740

using namespace std;
using namespace XGenSplineAPI;

void GetSplineData(string description, SplineData &splineData, unsigned int step = 0, bool debug = false);
void GetSplineData(string description, SplineDataMap &splineDataMap, unsigned int step = 0, bool debug = false);

void GetSplineRootPoints(string description, MPointArray &pointArray, unsigned int step = 0, bool debug = false);
void GetSplineRootPoints(string description, PointArrayMap &pointArrayMap, unsigned int step = 0, bool debug = false);

void GetSplineRootNormals(string description, VectorArrayMap &vectorArrayMap, unsigned int step = 0, bool debug = false);
void GetSplineRootNormals(string description, MVectorArray &vectorArray, unsigned int step = 0, bool debug = false);

void GetSplineRootPointsAndNormals(string description, MPointArray &pointArray, MVectorArray &vectorArray, unsigned int step = 0, bool debug = false);

void GetSplineBaseNode(MObject &desc, MObject &splineBase);

MSelectionList GetSplineBaseMesh(MObject splineBase);

int GetSplineBaseSegement(MObject splineBase);

class XGenHelper
{
public:
    XGenHelper() = default;
    XGenHelper(MObject &desc);
    XGenHelper(MDagPath &descPath);
    XGenHelper(string descName);
    ~XGenHelper();

    void GetSplineData(SplineDataMap &splineDataMap, unsigned int step = 0);
    void GetSplineRootPoints(PointArrayMap &pointArrayMap, unsigned int step = 0);
    void GetSplineRootNormals(VectorArrayMap &vectorArrayMap, unsigned int step = 0);
    void GetSplineRootPointsAndNormals(MPointArray &pointArray, MVectorArray &vectorArray, unsigned int step = 0);
    MObjectArray GetSplineBaseMesh();
    int GetBaseSegment();
    // void GetSplineBase();
    // void GetSplineBase(MObject &splineBase);
    MObject GetSplineBase();
    void SetDebug(bool debug) { m_debug = debug; };
    bool HasBoundMesh();
    MObject &Get() { return m_description; };
    MDagPath &GetDescDagPath() { return m_descPath; };
    MString GetDescName(bool fullPathName = false);
    MString GetSplineBaseName();

private:
    MObject m_description;
    MDagPath m_descPath;
    // MObject m_splineBase;
    bool m_debug;
};