syntax = "proto3";

// Generic package namespace for Wasot protocol definitions
package wasot;

////////// Events - Core Wasot event system /////////////

// Main event wrapper
message WasotEvent {
  oneof event {
    BlockStartedEvent block_started = 1;
    BlockFinishedEvent block_finished = 2;
    TextEvent text_finished = 3;
    ContextLineEvent context_line = 4;
  }
}

// Block events
message BlockStartedEvent {
  MetaLine meta_line = 1;
}

message BlockFinishedEvent {
}

// Context line event - metadata that doesn't participate in the content hierarchy
message ContextLineEvent {
  MetaLine meta_line = 1;
}

// Text events
message TextEvent {
  repeated string lines = 1;
  repeated LinksPerLine links = 2;
  repeated Footnote footnotes = 3;
}

message LinksPerLine {
  repeated Link links = 1;
}

// Core data structures
message MetaLine {
  string type_name = 1;
  uint32 level = 2;
  optional uint32 line_index = 3;
  QuotedText inline_text = 4;
  Arguments arguments = 5;
  optional string block_id = 6;
  bool is_void = 7;
}

message Arguments {
  QuotedText inline_text = 1;
  repeated QuotedText args = 2;
  repeated KeyValuePair kwargs = 3;
}

message KeyValuePair {
  QuotedText key = 1;
  QuotedText value = 2;
}

message QuotedText {
  string content = 1;
  bool quoted = 2;
  repeated Link links = 3;
}

// Document ID reference for cross-document links
message DocumentIdReference {
  string document_id = 1;
  string local_id = 2;
  optional string document_path = 3;
}

// Link data structure
message Link {
  optional QuotedText name = 1;
  optional string target = 2;
  Arguments arguments = 3;
  TargetType target_type = 4;
  uint32 start_index = 5;
  uint32 length = 6;
  optional DocumentIdReference document_ref = 7;
}

enum TargetType {
  URI = 0;
  FOOTNOTE = 1;
  ID = 2;
  ID_IN_DOCUMENT = 3;
}

// Footnote data structure
message Footnote {
  uint32 marker = 1;
  string link = 2;
}
