/**
 * Copyright (c) 2021 OceanBase
 * OceanBase CE is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#ifndef OCEANBASE_TRANSACTION_OB_TRANS_MSG_TYPE2_
#define OCEANBASE_TRANSACTION_OB_TRANS_MSG_TYPE2_

namespace oceanbase {
namespace transaction {

enum ObTransMsgType2 {
  OB_TRX_MSG_UNKNOWN = -1,

  OB_TRX_COMMIT_REQUEST = 0,
  OB_TRX_COMMIT_RESPONSE = 10,
  OB_TRX_ABORT_REQUEST = 20,
  OB_TRX_ABORT_RESPONSE = 30,

  OB_TRX_STMT_CREATE_CTX_REQUEST = 40,
  OB_TRX_STMT_CREATE_CTX_RESPONSE = 50,
  OB_TRX_STMT_ROLLBACK_REQUEST = 60,
  OB_TRX_STMT_ROLLBACK_RESPONSE = 70,
  OB_TRX_CLEAR_REQUEST = 80,
  OB_TRX_CLEAR_RESPONSE = 90,
  OB_TRX_START_STMT_REQUEST = 100,
  OB_TRX_START_STMT_RESPONSE = 110,
  OB_TRX_DISCARD_REQUEST = 120,
  OB_TRX_ASK_SCHEDULER_STATUS_REQUEST = 140,
  OB_TRX_ASK_SCHEDULER_STATUS_RESPONSE = 150,
  OB_TRX_SAVEPOINT_ROLLBACK_REQUEST = 160,
  OB_TRX_SAVEPOINT_ROLLBACK_RESPONSE = 170,

  OB_TRX_2PC_LOG_ID_REQUEST = 200,
  OB_TRX_2PC_LOG_ID_RESPONSE = 210,
  OB_TRX_2PC_PRE_PREPARE_REQUEST = 220,
  OB_TRX_2PC_PRE_PREPARE_RESPONSE = 230,
  OB_TRX_2PC_PREPARE_REQUEST = 240,
  OB_TRX_2PC_PREPARE_RESPONSE = 250,
  OB_TRX_2PC_PRE_COMMIT_REQUEST = 260,
  OB_TRX_2PC_PRE_COMMIT_RESPONSE = 270,
  OB_TRX_2PC_COMMIT_REQUEST = 280,
  OB_TRX_2PC_COMMIT_RESPONSE = 290,
  OB_TRX_2PC_ABORT_REQUEST = 300,
  OB_TRX_2PC_ABORT_RESPONSE = 310,
  OB_TRX_2PC_CLEAR_REQUEST = 320,
  OB_TRX_2PC_CLEAR_RESPONSE = 330,
  OB_TRX_2PC_COMMIT_CLEAR_REQUEST = 340,
  OB_TRX_2PC_COMMIT_CLEAR_RESPONSE = 350,

  OB_TRX_LISTENER_COMMIT_REQUEST = 360,
  OB_TRX_LISTENER_COMMIT_RESPONSE = 361,
  OB_TRX_LISTENER_ABORT_REQUEST = 362,
  OB_TRX_LISTENER_ABORT_RESPONSE = 363,
  OB_TRX_LISTENER_CLEAR_REQUEST = 364,
  OB_TRX_LISTENER_CLEAR_RESPONSE = 365,

  OB_TRX_SP_REQUEST = 400,
  OB_TRX_SP_RESPONSE = 410,

  OB_TRX_ERROR_MSG = 500
};

class ObTransMsgType2Checker {
public:
  static bool is_valid_msg_type(const int64_t msg_type)
  {
    return OB_TRX_2PC_CLEAR_REQUEST == msg_type || OB_TRX_2PC_CLEAR_RESPONSE == msg_type ||
           OB_TRX_2PC_ABORT_REQUEST == msg_type || OB_TRX_2PC_ABORT_RESPONSE == msg_type ||
           OB_TRX_2PC_COMMIT_REQUEST == msg_type || OB_TRX_2PC_COMMIT_RESPONSE == msg_type ||
           OB_TRX_2PC_PRE_COMMIT_REQUEST == msg_type || OB_TRX_2PC_PRE_COMMIT_RESPONSE == msg_type ||
           OB_TRX_2PC_PREPARE_REQUEST == msg_type || OB_TRX_2PC_PREPARE_RESPONSE == msg_type ||
           OB_TRX_LISTENER_COMMIT_REQUEST == msg_type || OB_TRX_LISTENER_COMMIT_RESPONSE == msg_type ||
           OB_TRX_LISTENER_ABORT_REQUEST == msg_type || OB_TRX_LISTENER_ABORT_RESPONSE == msg_type;
  }
  static bool is_request(const int64_t msg_type)
  {
    return OB_TRX_2PC_CLEAR_REQUEST == msg_type || OB_TRX_2PC_ABORT_REQUEST == msg_type ||
           OB_TRX_2PC_COMMIT_REQUEST == msg_type || OB_TRX_2PC_PREPARE_REQUEST == msg_type;
  }
  static bool is_listener_message(const int64_t msg_type)
  {
    return OB_TRX_LISTENER_COMMIT_REQUEST == msg_type || OB_TRX_LISTENER_COMMIT_RESPONSE == msg_type ||
           OB_TRX_LISTENER_ABORT_REQUEST == msg_type || OB_TRX_LISTENER_ABORT_RESPONSE == msg_type ||
           OB_TRX_LISTENER_CLEAR_REQUEST == msg_type || OB_TRX_LISTENER_CLEAR_RESPONSE == msg_type;
  }
};

}  // namespace transaction
}  // namespace oceanbase

#endif  // OCEANBASE_TRANSACTION_OB_TRANS_MSG_TYPE2_
