// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.

syntax = "proto3";
option go_package = "storj.io/common/pb";

package pointerdb;

import "google/protobuf/timestamp.proto";
import "gogo.proto";
import "orders.proto";

message RedundancyScheme {
  enum SchemeType {
    INVALID = 0;
    RS = 1;
  }
  SchemeType type = 1;

  // these values apply to RS encoding
  int32 min_req = 2; // minimum required for reconstruction
  int32 total = 3;   // total amount of pieces we generated
  int32 repair_threshold = 4;  // amount of pieces we need to drop to before triggering repair
  int32 success_threshold = 5; // amount of pieces we need to store to call it a success

  int32 erasure_share_size = 6;
}

message RemotePiece {
  int32 piece_num = 1;
  bytes node_id = 2 [(gogoproto.customtype) = "NodeID", (gogoproto.nullable) = false];
  orders.PieceHash hash = 3;
}

message RemoteSegment {
  RedundancyScheme redundancy = 1;
  bytes root_piece_id = 2 [(gogoproto.customtype) = "PieceID", (gogoproto.nullable) = false];
  repeated RemotePiece remote_pieces = 3;
  bytes merkle_root = 4; // root hash of the hashes of all of these pieces
}

message Pointer {
  enum DataType {
    INLINE = 0;
    REMOTE = 1;
  }

  DataType type = 1;

  bytes inline_segment = 3;
  RemoteSegment remote = 4;
  int64 segment_size = 5;

  google.protobuf.Timestamp creation_date = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
  google.protobuf.Timestamp expiration_date = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];

  bytes metadata = 8;

  google.protobuf.Timestamp last_repaired = 9 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
  int32 repair_count = 10;
  bool piece_hashes_verified = 11;
}

message ListResponse {
  message Item {
    string  path = 1;
    Pointer pointer = 2;
    bool    is_prefix = 3;
  }
  
  repeated Item items = 1;
  bool more = 2;
}
