syntax = "proto3";

package devvit.gateway.v1alpha;

import "devvit/dev_portal/installation/installation.proto";
import "devvit/triggers/v1alpha/triggers.proto";
import "google/protobuf/empty.proto";

option go_package = "github.snooguts.net/reddit/reddit-devplatform-monorepo/go-common/generated/protos/types/devvit/gateway";

service Triggers {
  rpc OnTrigger(devvit.data.triggers.v1alpha.TriggerEvent) returns (TriggerResponse);
  rpc OnFanOut(devvit.data.triggers.v1alpha.TriggerEvent) returns (TriggerFanOutResponse);
  rpc OnInvoke(TriggerInvocation) returns (google.protobuf.Empty);
  rpc OnInstall(devvit.dev_portal.installation.InstallationInfo) returns (google.protobuf.Empty);
  rpc OnUninstall(devvit.dev_portal.installation.InstallationInfo) returns (google.protobuf.Empty);
  rpc OnInstallChanged(devvit.dev_portal.installation.InstallationInfo) returns (google.protobuf.Empty);
}
enum Source {
  SNOORON_WORKER_DEVVIT = 0;
  EVALUATOR = 1;
}

message TriggerResponse {
  // total number of apps invoked
  int32 total = 1;
  // successful installation ids
  repeated string success = 2;
  // map of installation ids to error message
  map<string, string> errors = 3;
}

message TriggerFanOutResponse {
  // installation id of apps to invoke
  repeated string installation_ids = 1;
}

message TriggerInvocation {
  string installation_id = 1;
  devvit.data.triggers.v1alpha.TriggerEvent evt = 2;
  Source source = 3;
}
