syntax = "proto3";

package apf.ai.v1;

import "common.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Apf.Ai.Grpc.V1";

// Document ingestion. Every chunk must carry an explicit ACL: empty
// ACL is default-deny and rejected with InvalidArgument (gRPC) /
// 422 (HTTP).
service IngestionService {
  rpc IngestDocument(IngestDocumentRequest) returns (IngestDocumentResponse);
  rpc GetDocument(GetDocumentRequest) returns (DocumentSummary);
  rpc DeleteDocument(DeleteDocumentRequest) returns (DeleteDocumentResponse);
}

message IngestChunk {
  string content = 1;
  google.protobuf.Struct metadata = 2;
  AclSpec acl = 3;
}

message IngestDocumentRequest {
  string source = 1;
  string external_id = 2;
  string title = 3;
  repeated IngestChunk chunks = 4;
  Principal principal = 5;
}

message IngestDocumentResponse {
  string document_id = 1;
  int32 chunks_ingested = 2;
}

message GetDocumentRequest {
  string id = 1;
}

message DocumentSummary {
  string id = 1;
  string source_uri = 2;
  string title = 3;
  string external_id = 4;
  google.protobuf.Timestamp ingested_at = 5;
  int32 chunk_count = 6;
}

message DeleteDocumentRequest {
  string id = 1;
}

message DeleteDocumentResponse {
  bool deleted = 1;
}
