#pragma once
// vehicle_gateway_server.hpp
// 车端统一 WiFi6/TCP 入口。现场车间电脑优先连接这个端口。

#include <atomic>
#include <cstdint>

#include "chassis_handler.hpp"
#include "control_handler.hpp"
#include "external_pose_store.hpp"
#include "frame_codec.hpp"

namespace vaw
{

class VehicleGatewayServer
{
public:
    VehicleGatewayServer(
        uint16_t port,
        ChassisHandler* chassis_handler,
        ControlHandler* control_handler,
        ExternalPoseStore* external_pose_store);
    ~VehicleGatewayServer();

    // 阻塞运行，直到 stop() 被调用。
    void run();
    void stop();

private:
    void handle_connection(sock_t conn);
    MsgType response_type_for(MsgType request_type) const;
    void send_error_response(sock_t conn, MsgType response_type, const std::string& message) const;

    uint16_t port_;
    ChassisHandler* chassis_handler_;
    ControlHandler* control_handler_;
    ExternalPoseStore* external_pose_store_;
    std::atomic<bool> running_;
    sock_t listen_sock_;
};

}  // namespace vaw
