// Copyright 2023 Greptime Team
//
// 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.

syntax = "proto3";

package greptime.v1.meta;

option go_package = "github.com/GreptimeTeam/greptime-proto/go/greptime/v1/meta";

import "greptime/v1/meta/common.proto";
import "greptime/v1/common.proto";

message TableRoute {
  Table table = 1;
  repeated RegionRoute region_routes = 2;
}

message RegionRoute {
  Region region = 1;
  // single leader node for write task
  uint64 leader_peer_index = 2;
  // multiple follower nodes for read task
  repeated uint64 follower_peer_indexes = 3;
}

message Table {
  uint64 id = 1;
  TableName table_name = 2;
  bytes table_schema = 3;
}

message Region {
  // TODO(LFC): Maybe use message RegionNumber?
  uint64 id = 1;
  string name = 2;
  Partition partition = 3;

  map<string, string> attrs = 100;
}

// PARTITION `region_name` VALUES LESS THAN (value_list)
message Partition {
  repeated bytes column_list = 1;
  repeated bytes value_list = 2;
}

// This message is only for saving into store.
// TODO(weny): Remove it, Now, the upgrade tool is still dependent on it.
message TableRouteValue {
  repeated Peer peers = 1;
  TableRoute table_route = 2;
}