//
// Copyright 2022 DMetaSoul
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#pragma once

#include <string>

//
// ``node_role.h`` defines enum ``NodeRole`` to represent Parameter Server
// node roles and some helper functions to convert ``NodeRole`` values.
//
//

namespace metaspore {

//
// Use the X Macro technique to simplify code. See the following page
// for more information about X Macros:
//
//   https://en.wikipedia.org/wiki/X_Macro
//

#define METASPORE_NODE_ROLES(X)                                                                    \
    X(Coordinator)                                                                                 \
    X(Server)                                                                                      \
    X(Worker)                                                                                      \
    /**/

enum class NodeRole {
#undef METASPORE_NODE_ROLE_DEF
#define METASPORE_NODE_ROLE_DEF(n) n,
    METASPORE_NODE_ROLES(METASPORE_NODE_ROLE_DEF)
};

// A missing ``NodeRole`` is represented by ``NodeRole(-1)``.
constexpr NodeRole NullNodeRole = static_cast<NodeRole>(-1);
constexpr const char *NullNodeRoleString = "null";

// Functions to convert ``NodeRole`` to and from strings.
std::string NodeRoleToString(NodeRole role);
NodeRole NodeRoleFromString(const std::string &str);

std::string NullableNodeRoleToString(NodeRole role);
NodeRole NullableNodeRoleFromString(const std::string &str);

} // namespace metaspore
