syntax = "proto3";

// If you make any changes make sure you run: make regenerate-proto

package gitlab.agent.job_router.rpc;

option go_package = "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v18/internal/module/job_router/rpc";

import "buf/validate/validate.proto";

message GetJobRequest {
  // JSON containing the payload to send to the main GitLab application to retrieve CI jobs.
  // We treat this as a black box (at least for now).
  bytes job_request = 1 [(buf.validate.field).bytes.min_len = 1];
}

message GetJobResponse {
  // JSON response from the main GitLab application.
  // We treat this as a black box (at least for now).
  // Can be empty for No Content responses.
  bytes job_response = 1;
}

// JobResponse is a view into the GetJobResponse.job_response for fields that we are interested in
// We are interested in fields that:
// - are relevant to correlate a request (like a job id for logging)
// - admission controller request data
message JobResponse {
  int64 job_id = 1 [json_name = "id"];
  string job_token = 2 [json_name = "token"];

  JobInfo job_info = 3 [json_name = "job_info", (buf.validate.field).required = true];
  JobImage job_image = 4 [json_name = "image"];
}

message JobInfo {
  int64 project_id = 1 [json_name = "project_id"];
  string project_name = 2 [json_name = "project_name"];
  string project_full_path = 3 [json_name = "project_full_path"];
  int64 namespace_id = 4 [json_name = "namespace_id"];
  int64 root_namespace_id = 5 [json_name = "root_namespace_id"];
  int64 organization_id = 6 [json_name = "organization_id"];
  int64 user_id = 7 [json_name = "user_id"];
}

message JobImage {
  string name = 1 [json_name = "name"];
}

service JobRouter {
  // GetJob allows Runner to request a job.
  rpc GetJob (GetJobRequest) returns (GetJobResponse) {
  }
}
