// CompleteJsonExporter.h
#ifndef COMPLETE_JSON_EXPORTER_H
#define COMPLETE_JSON_EXPORTER_H

#include "QuadrupedRobotSimulation/BaseClass.h"
#include "QuadrupedRobotSimulation/KinematicsSimulation.h"
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <iomanip>

class CompleteJsonExporter
{
public:
    // 主导出函数
    static std::string ExportCompleteDataJsonString(const QuadrupedRobotSimulation &simulation);

    // 各个组件的创建函数
    static GaitInfo CreateGaitInfo(const QuadrupedRobotSimulation &simulation);
    static SystemParameters CreateSystemParameters(const QuadrupedRobotSimulation &simulation);
    static TrajectoryData CreateTrajectoryData(const QuadrupedRobotSimulation &simulation);
    static MotorDataExport CreateMotorData(const QuadrupedRobotSimulation &simulation);
    static ConstraintData CreateConstraintData(const QuadrupedRobotSimulation &simulation);
    static StatisticsData CreateStatistics(const QuadrupedRobotSimulation &simulation);
    static InitialAnglesData CreateInitialAngles(const QuadrupedRobotSimulation &simulation);
    static PhaseInfo CreatePhaseInfo(const QuadrupedRobotSimulation &simulation);
    static MotionRangeData CreateMotionRange(const QuadrupedRobotSimulation &simulation);

private:
    // 辅助函数
    static Point2D ArrayToPoint(const std::vector<double> &array);

    // 查找最小值和最大值的模板函数
    template <typename T>
    static T FindMin(const std::vector<T> &values);

    template <typename T>
    static T FindMax(const std::vector<T> &values);

    // 检查所有值是否满足条件的模板函数
    template <typename T>
    static bool All(const std::vector<T> &values, std::function<bool(const T &)> predicate);

    // 转换函数
    static std::string DoubleToString(double value, int precision = 6);
};

#endif // COMPLETE_JSON_EXPORTER_H
