syntax = "proto3";

package polyglot.project.v1;

// Discovery, dependency resolution, and translation for published fixture builds.
service ProjectService {
  rpc ListCapabilities(ListCapabilitiesRequest) returns (ListCapabilitiesResponse);
  rpc ResolveProject(ResolveProjectRequest) returns (ResolveProjectResponse);
  rpc SubmitTranslation(SubmitTranslationRequest) returns (SubmitTranslationResponse);
  rpc GetTranslation(GetTranslationRequest) returns (GetTranslationResponse);
}

enum Language {
  LANGUAGE_UNSPECIFIED = 0;
  LANGUAGE_TYPESCRIPT = 1;
  LANGUAGE_RUST_WASM = 2;
  LANGUAGE_PYTHON = 3;
  LANGUAGE_JAVASCRIPT = 4;
  LANGUAGE_C = 5;
  LANGUAGE_JAVA = 6;
  LANGUAGE_SQL = 7;
  LANGUAGE_LATEX = 8;
  LANGUAGE_RUST = 9;
}

enum Stage {
  STAGE_UNSPECIFIED = 0;
  STAGE_RESOLVE = 1;
  STAGE_TRANSLATE = 2;
  STAGE_COMPILE = 3;
  STAGE_VERIFY = 4;
}

message Direction {
  Language source = 1;
  Language destination = 2;
}

message LanguageInfo {
  Language language = 1;
  string label = 2;
}

message Capability {
  Direction direction = 1;
  repeated Stage stages = 2;
  string qualification = 3;
}

message Tool {
  string name = 1;
  string description = 2;
  repeated Language languages = 3;
  bool available_in_preview = 4;
}

message Project {
  string id = 1;
  string title = 2;
}

message ListCapabilitiesRequest {}

message ListCapabilitiesResponse {
  string catalog_revision = 1;
  repeated Project projects = 2;
  repeated LanguageInfo languages = 3;
  repeated Capability capabilities = 4;
  repeated Tool tools = 5;
}

message ProjectFile {
  string path = 1;
  string content = 2;
}

message Dependency {
  string importer = 1;
  string imported = 2;
  repeated string bindings = 3;
}

message ProjectGraph {
  string entry_point = 1;
  repeated ProjectFile files = 2;
  repeated Dependency dependencies = 3;
  string input_digest = 4;
}

message ResolveProjectRequest {
  string project_id = 1;
  Language source = 2;
}

message ResolveProjectResponse {
  ProjectGraph graph = 1;
}

message SubmitTranslationRequest {
  string project_id = 1;
  Direction direction = 2;
}

message SubmitTranslationResponse {
  TranslationJob job = 1;
}

message GetTranslationRequest {
  string job_id = 1;
}

message GetTranslationResponse {
  TranslationJob job = 1;
}

enum JobState {
  JOB_STATE_UNSPECIFIED = 0;
  JOB_STATE_SUCCEEDED = 1;
}

message Artifact {
  string path = 1;
  string sha256 = 2;
}

message FilePair {
  string source_path = 1;
  ProjectFile generated = 2;
}

message Verification {
  repeated string passed_actions = 1;
  uint32 compared_states = 2;
}

message Diagnostic {
  string path = 1;
  uint32 line = 2;
  uint32 column = 3;
  string message = 4;
}

message TranslationJob {
  string id = 1;
  JobState state = 2;
  string project_id = 3;
  Direction direction = 4;
  string input_digest = 5;
  string catalog_revision = 6;
  repeated FilePair files = 7;
  repeated Artifact artifacts = 8;
  Verification verification = 9;
  repeated Diagnostic diagnostics = 10;
}

// Build-time snapshot used to serve immutable translation jobs.
message PublishedProject {
  ListCapabilitiesResponse catalog = 1;
  repeated PublishedGraph graphs = 2;
  repeated TranslationJob jobs = 3;
}

message PublishedGraph {
  Language source = 1;
  ProjectGraph graph = 2;
}

// Request-scoped translations over submitted files.
service LiveTranslationService {
  rpc Translate(TranslateRequest) returns (stream TranslateResponse);
}

message TranslateRequest {
  string entry_point = 1;
  repeated ProjectFile files = 2;
}

message TranslateResponse {
  string job_id = 1;
  oneof event {
    Stage progress = 2;
    ProjectGraph graph = 3;
    LiveTranslationResult result = 4;
    LiveTranslationFailure failure = 5;
  }
}

message LiveTranslationResult {
  repeated FilePair files = 1;
}

message LiveTranslationFailure {
  repeated Diagnostic diagnostics = 1;
}
