#include <doctest/doctest.h>

#include "fgc/CommandParser.h"

using namespace fgc;

TEST_CASE("parseCommand handles single-verb commands") {
    auto c = parseCommand("start");
    CHECK(c.verb == "start");
    CHECK(c.device.empty());
    CHECK_FALSE(c.has_value);
}

TEST_CASE("parseCommand splits device and trailing numeric value") {
    auto c = parseCommand("set fps 5");
    CHECK(c.verb == "set");
    CHECK(c.device == "fps");
    CHECK(c.option.empty());
    CHECK(c.has_value);
    CHECK(c.value == doctest::Approx(5.0));
}

TEST_CASE("parseCommand keeps option plus value") {
    auto c = parseCommand("set camera jxlq 2");
    CHECK(c.device == "camera");
    CHECK(c.option == "jxlq");
    CHECK(c.value == doctest::Approx(2.0));
}

TEST_CASE("parseCommand keeps non-numeric option (raw motor command)") {
    auto c = parseCommand("set motorctl kd180");
    CHECK(c.device == "motorctl");
    CHECK(c.option == "kd180");
    CHECK_FALSE(c.has_value);
}

TEST_CASE("parseCommand on empty input") {
    CHECK(parseCommand("").empty());
    CHECK(parseCommand("   ").empty());
}
