// Buffer service for content access.
//
// Philosophy: Returns raw buffer data without rendering.
// No gutters, no line numbers, no decorations.
// Client decides how to render the content.

syntax = "proto3";
package reovim.v2;

service BufferService {
  // Get raw buffer content as text lines.
  rpc GetRawContent(GetRawContentRequest) returns (GetRawContentResponse);

  // Get buffer line count (efficient, no content transfer).
  rpc GetLineCount(GetLineCountRequest) returns (GetLineCountResponse);

  // Get line annotations (diagnostics, git signs, etc.).
  rpc GetAnnotations(GetAnnotationsRequest) returns (GetAnnotationsResponse);

  // List all open buffers.
  rpc List(ListBuffersRequest) returns (ListBuffersResponse);

  // Open a file into a buffer.
  rpc OpenFile(OpenFileRequest) returns (OpenFileResponse);

  // Write buffer to file.
  rpc WriteFile(WriteFileRequest) returns (WriteFileResponse);

  // Set buffer content.
  rpc SetContent(SetContentRequest) returns (SetContentResponse);
}

// Raw content

message GetRawContentRequest {
  optional uint64 buffer_id = 1;   // Default: active buffer
  optional uint64 start_line = 2;  // Default: 0
  optional uint64 end_line = 3;    // Default: end of buffer
}

message GetRawContentResponse {
  uint64 buffer_id = 1;
  repeated string lines = 2;    // Raw text lines (no gutter, no styling)
  uint64 start_line = 3;        // Start line of returned content
  uint64 total_lines = 4;       // Total lines in buffer
}

// Line count

message GetLineCountRequest {
  optional uint64 buffer_id = 1;  // Default: active buffer
}

message GetLineCountResponse {
  uint64 buffer_id = 1;
  uint64 line_count = 2;
}

// Annotations

message GetAnnotationsRequest {
  optional uint64 buffer_id = 1;
  optional uint64 start_line = 2;
  optional uint64 end_line = 3;
}

message GetAnnotationsResponse {
  uint64 buffer_id = 1;
  repeated LineAnnotation annotations = 2;
}

message LineAnnotation {
  uint64 line = 1;
  string kind = 2;      // "diagnostic", "git_sign", "breakpoint", "fold"
  string text = 3;      // Symbol or text to display
  optional uint32 severity = 4;  // 1=error, 2=warning, 3=info, 4=hint
  optional string color = 5;     // CSS hex (#ff0000) or named color
}

// Buffer list

message ListBuffersRequest {}

message ListBuffersResponse {
  repeated BufferInfo buffers = 1;
}

message BufferInfo {
  uint64 id = 1;
  optional string path = 2;      // File path (if file-backed)
  string name = 3;               // Display name
  bool modified = 4;             // Has unsaved changes
  uint64 line_count = 5;
  optional string content_type = 6;  // Codec content type (e.g., "text/utf-8")
  optional bool readonly = 7;       // Read-only (lossy codec decode)
  optional CodecMetadata codec_metadata = 8;
}

message CodecMetadata {
  string codec_name = 1;            // Codec that decoded this buffer
  optional string line_ending = 2;  // Line ending style ("lf", "crlf")
  bool has_bom = 3;                 // File had a byte order mark
}

// File operations

message OpenFileRequest {
  string path = 1;
}

message OpenFileResponse {
  uint64 buffer_id = 1;
  bool ok = 2;
  optional string error = 3;
}

message WriteFileRequest {
  optional uint64 buffer_id = 1;  // Default: active buffer
  optional string path = 2;       // Default: buffer's current path
}

message WriteFileResponse {
  bool ok = 1;
  optional string error = 2;
}

message SetContentRequest {
  optional uint64 buffer_id = 1;
  string content = 2;
}

message SetContentResponse {
  bool ok = 1;
}
