#pragma once
// chassis_handler.hpp
// 底盘处理器虚基类。
// 子类覆盖各方法后即可接入真实底盘驱动；默认实现返回 stub 成功响应。

#include <chrono>
#include "data_types.hpp"

namespace vaw
{

class ChassisHandler
{
public:
    virtual ~ChassisHandler() = default;

    // 查询底盘就绪状态
    // req: CHASSIS_GET_READINESS_REQ 解析结果（AgentReadinessRequest 字段）
    virtual ChassisReadinessResponse get_readiness(const nlohmann::json& req)
    {
        ChassisReadinessResponse rsp;
        rsp.success               = true;
        rsp.error_code            = ErrorCode::OK;
        rsp.message               = "底盘就绪（stub）";
        rsp.agent_ready           = true;
        rsp.chassis_driver_online = true;
        rsp.motion_control_ready  = true;
        rsp.estop_released        = true;
        rsp.vehicle_safe_to_move  = true;
        rsp.telemetry_available   = true;
        rsp.checked_timestamp_us  = std::chrono::duration_cast<std::chrono::microseconds>(
            std::chrono::system_clock::now().time_since_epoch()).count();
        return rsp;
    }

    // 执行底盘动作原语
    // req: 已解析的 MotionPrimitiveRequest
    virtual ChassisJobResult execute_motion_primitive(const MotionPrimitiveRequest& req)
    {
        (void)req;
        ChassisJobResult result;
        result.success              = true;
        result.error_code           = ErrorCode::OK;
        result.message              = "动作原语执行完成（stub）";
        result.job_id               = req.test_case_id;
        result.data_quality_passed  = true;
        result.suitable_for_commit  = true;
        result.validation_summary.auto_acceptance_passed = true;
        return result;
    }

    // 紧急制动
    // req: CHASSIS_EMERGENCY_BRAKE_REQ payload
    virtual nlohmann::json emergency_brake(const nlohmann::json& req)
    {
        (void)req;
        return nlohmann::json{
            {"success",    true},
            {"error_code", {"code", 0}},
            {"message",    "紧急制动已执行（stub）"},
        };
    }
};

}  // namespace vaw
