// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

syntax = "proto3";

package dapr.proto.runtime.v1;

import "google/protobuf/any.proto";
import "google/protobuf/empty.proto";
import "dapr/proto/common/v1/common.proto";

option csharp_namespace = "Dapr.Client.Autogen.Grpc.v1";
option java_outer_classname = "DaprProtos";
option java_package = "io.dapr.v1";
option go_package = "github.com/dapr/dapr/pkg/proto/runtime/v1;runtime";

// Dapr service provides APIs to user application to access Dapr building blocks.
service Dapr {
  // Invokes a method on a remote Dapr app.
  rpc InvokeService(InvokeServiceRequest) returns (common.v1.InvokeResponse) {}

  // Gets the state for a specific key.
  rpc GetState(GetStateRequest) returns (GetStateResponse) {}

  // Gets a bulk of state items for a list of keys
  rpc GetBulkState(GetBulkStateRequest) returns (GetBulkStateResponse) {}

  // Saves the state for a specific key.
  rpc SaveState(SaveStateRequest) returns (google.protobuf.Empty) {}

  // Deletes the state for a specific key.
  rpc DeleteState(DeleteStateRequest) returns (google.protobuf.Empty) {}

  // Deletes a bulk of state items for a list of keys
  rpc DeleteBulkState(DeleteBulkStateRequest) returns (google.protobuf.Empty) {}

  // Executes transactions for a specified store
  rpc ExecuteStateTransaction(ExecuteStateTransactionRequest) returns (google.protobuf.Empty) {}

  // Publishes events to the specific topic.
  rpc PublishEvent(PublishEventRequest) returns (google.protobuf.Empty) {}

  // Invokes binding data to specific output bindings
  rpc InvokeBinding(InvokeBindingRequest) returns (InvokeBindingResponse) {}

  // Gets secrets from secret stores.
  rpc GetSecret(GetSecretRequest) returns (GetSecretResponse) {}

  // Gets a bulk of secrets
  rpc GetBulkSecret(GetBulkSecretRequest) returns (GetBulkSecretResponse) {}

  // Register an actor timer.
  rpc RegisterActorTimer(RegisterActorTimerRequest) returns (google.protobuf.Empty) {}

  // Unregister an actor timer.
  rpc UnregisterActorTimer(UnregisterActorTimerRequest) returns (google.protobuf.Empty) {}

  // Register an actor reminder.
  rpc RegisterActorReminder(RegisterActorReminderRequest) returns (google.protobuf.Empty) {}

  // Unregister an actor reminder.
  rpc UnregisterActorReminder(UnregisterActorReminderRequest) returns (google.protobuf.Empty) {}

  // Gets the state for a specific actor.
  rpc GetActorState(GetActorStateRequest) returns (GetActorStateResponse) {}

  // Executes state transactions for a specified actor
  rpc ExecuteActorStateTransaction(ExecuteActorStateTransactionRequest) returns (google.protobuf.Empty) {}

  // InvokeActor calls a method on an actor.
  rpc InvokeActor (InvokeActorRequest) returns (InvokeActorResponse) {}

  // Gets metadata of the sidecar
  rpc GetMetadata (google.protobuf.Empty) returns (GetMetadataResponse) {}

  // Sets value in extended metadata of the sidecar
  rpc SetMetadata (SetMetadataRequest) returns (google.protobuf.Empty) {}
}

// InvokeServiceRequest represents the request message for Service invocation.
message InvokeServiceRequest {
  // Required. Callee's app id.
  string id = 1;

  // Required. message which will be delivered to callee.
  common.v1.InvokeRequest message = 3;
}

// GetStateRequest is the message to get key-value states from specific state store.
message GetStateRequest {
  // The name of state store.
  string store_name = 1;

  // The key of the desired state
  string key = 2;

  // The read consistency of the state store.
  common.v1.StateOptions.StateConsistency consistency = 3;

  // The metadata which will be sent to state store components.
  map<string,string> metadata = 4;
}

// GetBulkStateRequest is the message to get a list of key-value states from specific state store.
message GetBulkStateRequest {
  // The name of state store.
  string store_name = 1;

  // The keys to get.
  repeated string keys = 2;

  // The number of parallel operations executed on the state store for a get operation.
  int32 parallelism = 3;

  // The metadata which will be sent to state store components.
  map<string,string> metadata = 4;
}

// GetBulkStateResponse is the response conveying the list of state values.
message GetBulkStateResponse {
  // The list of items containing the keys to get values for.
  repeated BulkStateItem items = 1;
}

// BulkStateItem is the response item for a bulk get operation.
// Return values include the item key, data and etag.
message BulkStateItem {
  // state item key
  string key = 1;

  // The byte array data
  bytes data = 2;

  // The entity tag which represents the specific version of data.
  // ETag format is defined by the corresponding data store.
  string etag = 3;

  // The error that was returned from the state store in case of a failed get operation.
  string error = 4;

  // The metadata which will be sent to app.
  map<string,string> metadata = 5;
}

// GetStateResponse is the response conveying the state value and etag.
message GetStateResponse {
  // The byte array data
  bytes data = 1;

  // The entity tag which represents the specific version of data.
  // ETag format is defined by the corresponding data store.
  string etag = 2;

  // The metadata which will be sent to app.
  map<string,string> metadata = 3;
}

// DeleteStateRequest is the message to delete key-value states in the specific state store.
message DeleteStateRequest {
  // The name of state store.
  string store_name = 1;

  // The key of the desired state
  string key = 2;

  // The entity tag which represents the specific version of data.
  // The exact ETag format is defined by the corresponding data store.
  common.v1.Etag etag = 3;

  // State operation options which includes concurrency/
  // consistency/retry_policy.
  common.v1.StateOptions options = 4;

  // The metadata which will be sent to state store components.
  map<string,string> metadata = 5;
}

// DeleteBulkStateRequest is the message to delete a list of key-value states from specific state store.
message DeleteBulkStateRequest {
  // The name of state store.
  string store_name = 1;

  // The array of the state key values.
  repeated common.v1.StateItem states = 2;
}

// SaveStateRequest is the message to save multiple states into state store.
message SaveStateRequest {
  // The name of state store.
  string store_name = 1;

  // The array of the state key values.
  repeated common.v1.StateItem states = 2;
}

// PublishEventRequest is the message to publish event data to pubsub topic
message PublishEventRequest {
  // The name of the pubsub component
  string pubsub_name = 1;

  // The pubsub topic
  string topic = 2;

  // The data which will be published to topic.
  bytes data = 3;

  // The content type for the data (optional).
  string data_content_type = 4;

  // The metadata passing to pub components
  //
  // metadata property:
  // - key : the key of the message.
  map<string,string> metadata = 5;
}

// InvokeBindingRequest is the message to send data to output bindings
message InvokeBindingRequest {
  // The name of the output binding to invoke.
  string name = 1;

  // The data which will be sent to output binding.
  bytes data = 2;

  // The metadata passing to output binding components
  // 
  // Common metadata property:
  // - ttlInSeconds : the time to live in seconds for the message. 
  // If set in the binding definition will cause all messages to 
  // have a default time to live. The message ttl overrides any value
  // in the binding definition.
  map<string,string> metadata = 3;

  // The name of the operation type for the binding to invoke
  string operation = 4;
}

// InvokeBindingResponse is the message returned from an output binding invocation
message InvokeBindingResponse {
  // The data which will be sent to output binding.
  bytes data = 1;

  // The metadata returned from an external system
  map<string,string> metadata = 2;
}

// GetSecretRequest is the message to get secret from secret store.
message GetSecretRequest {
  // The name of secret store.
  string store_name = 1;

  // The name of secret key.
  string key = 2;

  // The metadata which will be sent to secret store components.
  map<string,string> metadata = 3;
}

// GetSecretResponse is the response message to convey the requested secret.
message GetSecretResponse {
  // data is the secret value. Some secret store, such as kubernetes secret
  // store, can save multiple secrets for single secret key.
  map<string, string> data = 1;
}

// GetBulkSecretRequest is the message to get the secrets from secret store.
message GetBulkSecretRequest {
  // The name of secret store.
  string store_name = 1;

  // The metadata which will be sent to secret store components.
  map<string,string> metadata = 2;
}

// SecretResponse is a map of decrypted string/string values
message SecretResponse {
  map<string, string> secrets = 1;
}

// GetBulkSecretResponse is the response message to convey the requested secrets.
message GetBulkSecretResponse {
  // data hold the secret values. Some secret store, such as kubernetes secret
  // store, can save multiple secrets for single secret key.
  map<string, SecretResponse> data = 1;
}

// TransactionalStateOperation is the message to execute a specified operation with a key-value pair.
message TransactionalStateOperation {
  // The type of operation to be executed
  string operationType = 1;

  // State values to be operated on 
  common.v1.StateItem request = 2;
}

// ExecuteStateTransactionRequest is the message to execute multiple operations on a specified store.
message ExecuteStateTransactionRequest {
  // Required. name of state store.
  string storeName = 1;

  // Required. transactional operation list.
  repeated TransactionalStateOperation operations = 2;

  // The metadata used for transactional operations.
  map<string,string> metadata = 3;
}

// RegisterActorTimerRequest is the message to register a timer for an actor of a given type and id.
message RegisterActorTimerRequest {
  string actor_type = 1;
  string actor_id = 2;
  string name = 3;
  string due_time = 4;
  string period = 5;
  string callback = 6;
  bytes  data = 7;
}

// UnregisterActorTimerRequest is the message to unregister an actor timer
message UnregisterActorTimerRequest {
  string actor_type = 1;
  string actor_id = 2;
  string name = 3;
}

// RegisterActorReminderRequest is the message to register a reminder for an actor of a given type and id.
message RegisterActorReminderRequest {
  string actor_type = 1;
  string actor_id = 2;
  string name = 3;
  string due_time = 4;
  string period = 5;
  bytes  data = 6;
}

// UnregisterActorReminderRequest is the message to unregister an actor reminder.
message UnregisterActorReminderRequest {
  string actor_type = 1;
  string actor_id = 2;
  string name = 3;
}

// GetActorStateRequest is the message to get key-value states from specific actor.
message GetActorStateRequest {
  string actor_type = 1;
  string actor_id = 2;
  string key = 3;
}

// GetActorStateResponse is the response conveying the actor's state value.
message GetActorStateResponse {
  bytes data = 1;
}

// ExecuteActorStateTransactionRequest is the message to execute multiple operations on a specified actor.
message ExecuteActorStateTransactionRequest {
  string actor_type = 1;
  string actor_id = 2;
  repeated TransactionalActorStateOperation operations = 3;
}

// TransactionalAcorStateOperation is the message to execute a specified operation with a key-value pair.
message TransactionalActorStateOperation {
  string operationType = 1;
  string key = 2;
  google.protobuf.Any value = 3;
}

// InvokeActorRequest is the message to call an actor.
message InvokeActorRequest {
  string actor_type = 1;
  string actor_id = 2;
  string method = 3;
  bytes  data = 4;
}

// InvokeActorResponse is the method that returns an actor invocation response.
message InvokeActorResponse {
  bytes data = 1;
}

// GetMetadataResponse is a message that is returned on GetMetadata rpc call
message GetMetadataResponse {
  string id = 1;
  repeated ActiveActorsCount active_actors_count = 2;
  repeated RegisteredComponents registered_components = 3;
  map<string,string> extended_metadata = 4;
}

message ActiveActorsCount {
  string type = 1;
  int32 count = 2;
}

message RegisteredComponents {
  string name = 1;
  string type = 2;
  string version = 3;
}

message SetMetadataRequest {
  string key = 1;
  string value = 2;
}