aboutsummaryrefslogtreecommitdiff
path: root/src/wanda/command.cpp
blob: 960c52b154a00720db7bdf9daffec152c4628ad1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <wanda/command.hpp>

namespace wanda
{
  std::optional<message> command::message() const
  {
    using namespace std::string_literals;
    auto const command = [this] {
      switch (id)
      {
        case command_id::change:
          return "CHANGE"s;
        default:
          return ""s;
      }
    }();

    auto argument_string = std::string{};
    for (int index = 0ul; index < arguments.size(); ++index)
    {
      argument_string += (index) ? "," + arguments[index] : arguments[index];
    }

    if (command.empty())
    {
      return std::nullopt;
    }

    return wanda::message{"C", command, argument_string};
  }

  std::optional<command> make_command(message message)
  {
    if (message.command == "CHANGE")
    {
      return {{command_id::change}};
    }

    return std::nullopt;
  }

  command make_change_command()
  {
    return {command_id::change};
  }

}  // namespace wanda