syntax = "proto3";

package flipt.ofrep;

import "google/protobuf/struct.proto";
import "google/api/annotations.proto";
import "google/api/visibility.proto";
import "google/api/field_behavior.proto";
import "gnostic/openapi/v3/annotations.proto";

option go_package = "go.flipt.io/flipt/rpc/flipt/ofrep";

message GetProviderConfigurationRequest {}

message GetProviderConfigurationResponse {
  string name = 1;
  Capabilities capabilities = 2;
}

message Capabilities {
  CacheInvalidation cache_invalidation = 1;
  FlagEvaluation flag_evaluation = 2;
}

message CacheInvalidation {
  Polling polling = 1;
}

message Polling {
  bool enabled = 1;
  uint32 min_polling_interval_ms = 2;
}

message FlagEvaluation {
  repeated string supported_types = 1;
}

message EvaluateFlagRequest {
  string key = 1;
  map<string, string> context = 2;
}

message EvaluatedFlag {
  string key = 1;
  EvaluateReason reason = 2;
  string variant = 3;
  google.protobuf.Struct metadata = 4;
  google.protobuf.Value value = 5;
}

enum EvaluateReason {
  UNKNOWN = 0;
  DISABLED = 1;
  TARGETING_MATCH = 2;
  DEFAULT = 3;
}

message EvaluateBulkRequest {
  map<string, string> context = 2;
}

message BulkEvaluationResponse {
  repeated EvaluatedFlag flags = 1 [(google.api.field_behavior) = REQUIRED];
}

service OFREPService {
  option (google.api.api_visibility) = {restriction: "flipt:sdk:ignore"};
  // OFREP provider configuration
  rpc GetProviderConfiguration(GetProviderConfigurationRequest) returns (GetProviderConfigurationResponse) {
    option (google.api.http) = {get: "/ofrep/v1/configuration" };
    option (gnostic.openapi.v3.operation) = {operation_id: "ofrep.configuration"};
  }
  // OFREP single flag evaluation
  rpc EvaluateFlag(EvaluateFlagRequest) returns (EvaluatedFlag) {
    option (google.api.http) = {post: "/ofrep/v1/evaluate/flags/{key}" body: "*"};
    option (gnostic.openapi.v3.operation) = {operation_id: "ofrep.evaluateFlag"};
  }
  // OFREP bulk flag evaluation
  rpc EvaluateBulk(EvaluateBulkRequest) returns (BulkEvaluationResponse) {
    option (google.api.http) = {post: "/ofrep/v1/evaluate/flags" body: "*"};
    option (gnostic.openapi.v3.operation) = {operation_id: "ofrep.evaluateBulk"};
  }
}
