syntax = "proto3";

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

package gitlab.agent.autoflow.engine;

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

import "pkg/event/event.proto";

message HandleEventRequest {
  event.CloudEvent event = 1;
  event.Project flow_project = 2;
  map<string, string> variables = 3;
}

// Worklow Messages
message HandleEventWorkflowInput {
  event.CloudEvent event = 1;
  event.Project flow_project = 2;
  string entrypoint = 3;
  map<string, string> variables = 4;
}

message HandleEventWorkflowOutput {}

message RunEventHandlerWorkflowInput {
  event.CloudEvent event = 1;
  event.Project flow_project = 2;
  string entrypoint = 3;
  repeated ModuleSource modules = 4;
  uint32 handler = 5;
  string workflow_id_prefix = 6;
  map<string, string> variables = 7;
}

message RunEventHandlerWorkflowOutput {}

// Activity Messages
message LoadAllEventHandlersActivityInput {
  event.CloudEvent event = 1;
  event.Project flow_project = 2;
  string entrypoint = 3;
}

message LoadAllEventHandlersActivityOutput {
  repeated HandlerInfo handlers = 1;
  repeated ModuleSource modules = 2;
}

message HttpDoActivityInput {
  string method = 1;
  string url = 2;
  map<string, Values> header = 3;
  bytes body = 4;
}

message HttpDoActivityOutput {
  uint32 status_code = 1;
  string status = 2;
  map<string, Values> header = 3;
  bytes body = 4;
}

// TODO Protobuf map<> translate into Go map. Iteration order is not deterministic in Go maps so they must not be used.
// TODO Replace them with 'repeated KeyValue' or similar.

message ModuleSource {
  string source_name = 1;
  string file = 2;
  bytes data = 3;
}

message HandlerInfo {
  string workflow_id = 1;
}


message SignalPayload {
  // JSON-encoded Starlark value.
  string payload = 1;
}

message Values {
  repeated string value = 1;
}
