syntax = "proto3";

package confidence.flags.resolver.v1;

import "confidence/flags/resolver/v1/api.proto";
import "confidence/flags/resolver/v1/types.proto";

option java_package = "com.spotify.confidence.flags.resolver.v1";
option java_multiple_files = true;
option java_outer_classname = "WasmApiProto";


message ResolveProcessRequest {
  oneof resolve {
    // Materialization reads will "suspend" the resolve
    ResolveFlagsRequest deferred_materializations = 1;
    // Materializations will be read from a statically provided set
    StaticMaterializations static_materializations = 2;
    // No materialization support, reads will error the flag.
    ResolveFlagsRequest without_materializations = 3;

    // Resume a previously suspended resolve with requested materializations
    Resume resume = 4;
  }

  message StaticMaterializations {
    ResolveFlagsRequest resolve_request = 1;
    repeated MaterializationRecord materializations = 2;
  }

  message Resume {
    repeated MaterializationRecord materializations = 1;
    bytes state = 2;
  }
}


message ResolveProcessResponse {
  oneof result {
    Resolved resolved = 1;
    Suspended suspended = 2;
  }

  message Resolved {
    ResolveFlagsResponse response = 1;
    repeated MaterializationRecord materializations_to_write = 2;
    reserved 3;
  }

  message Suspended {
    repeated MaterializationRecord materializations_to_read = 1;
    bytes state = 2;
  }
}

// This message is used both as a query and a result when reading materializations.
// Records with a non-empty rule should be treated as variant reads; others as inclusion reads
message MaterializationRecord {
  string unit = 1;
  string materialization = 2;
  string rule = 3;
  string variant = 4;
}


message LogMessage {
  string message = 1;
}

message RegisterResolveRequest {
  ResolveReason reason = 1;
  uint32 latency_us = 2;
}
