include "uuid.fbs";
include "synopsis.fbs";

namespace vast.fbs.value_index;

table v0 {
  /// The type of the index.
  // TODO: This is currently deduced implicitly from the `combined_layout` of
  // the `Partition`. Once available, we want to use the `Type` flatbuffer here
  // so all relevant information is available.
  // type: Type;

  /// The serialized `vast::value_index`.
  data: [ubyte];
}

namespace vast.fbs.qualified_value_index;

table v0 {
  /// The full-qualified field name, e.g., "zeek.conn.id.orig_h".
  field_name: string;

  /// The value index for the given field.
  index: value_index.v0;
}

namespace vast.fbs.type_ids;

/// Stores the ids of a given type in the current partition.
/// Used to answer queries like `#type == "foo"`.
table v0 {
  /// The type name.
  name: string;

  /// The serialized `vast::ids`.
  ids: [ubyte];
}

namespace vast.fbs.partition;

/// A partition is a collection of indices and column synopses for some
/// id range.
table v0 {
  /// The UUID of this partition.
  uuid: uuid.v0;

  /// The first ID in the partition.
  offset: uint64;

  /// The number of contained events.
  events: uint64;

  /// The available layouts in this partition.
  /// TODO: Use the layout type once available.
  combined_layout: [ubyte];

  /// A map storing the mapping from type name -> ids
  type_ids: [type_ids.v0];

  /// Various synopsis structures for partition-wide synopses of certain
  /// columns. (eg. global min and max timestamp)
  partition_synopsis: partition_synopsis.v0;

  /// The contained value indexes.
  indexes: [qualified_value_index.v0];
}

union Partition {
  v0,
}

namespace vast.fbs;

table Partition {
  partition: partition.Partition;
}

root_type Partition;

file_identifier "VSTp";
