/*
Copyright 2021 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

syntax = "proto3";

package dapr.proto.common.v1;

import "google/protobuf/any.proto";

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

// HTTPExtension includes HTTP verb and querystring
// when Dapr runtime delivers HTTP content.
// 
// For example, when callers calls http invoke api
// POST http://localhost:3500/v1.0/invoke/<app_id>/method/<method>?query1=value1&query2=value2
// 
// Dapr runtime will parse POST as a verb and extract querystring to quersytring map.
message HTTPExtension {
  // Type of HTTP 1.1 Methods
  // RFC 7231: https://tools.ietf.org/html/rfc7231#page-24
  // RFC 5789: https://datatracker.ietf.org/doc/html/rfc5789
  enum Verb {
    NONE = 0;
    GET = 1;
    HEAD = 2;
    POST = 3;
    PUT = 4;
    DELETE = 5;
    CONNECT = 6;
    OPTIONS = 7;
    TRACE = 8;
    PATCH = 9;
  }

  // Required. HTTP verb.
  Verb verb = 1;

  // Optional. querystring represents an encoded HTTP url query string in the following format: name=value&name2=value2
  string querystring = 2;
}

// InvokeRequest is the message to invoke a method with the data.
// This message is used in InvokeService of Dapr gRPC Service and OnInvoke
// of AppCallback gRPC service.
message InvokeRequest {
  // Required. method is a method name which will be invoked by caller.
  string method = 1;

  // Required in unary RPCs. Bytes value or Protobuf message which caller sent.
  // Dapr treats Any.value as bytes type if Any.type_url is unset.
  google.protobuf.Any data = 2;

  // The type of data content.
  //
  // This field is required if data delivers http request body
  // Otherwise, this is optional.
  string content_type = 3;

  // HTTP specific fields if request conveys http-compatible request.
  //
  // This field is required for http-compatible request. Otherwise,
  // this field is optional.
  HTTPExtension http_extension = 4;
}

// InvokeResponse is the response message including data and its content type
// from app callback.
// This message is used in InvokeService of Dapr gRPC Service and OnInvoke
// of AppCallback gRPC service.
message InvokeResponse {
  // Required in unary RPCs. The content body of InvokeService response.
  google.protobuf.Any data = 1;

  // Required. The type of data content.
  string content_type = 2;
}

// Chunk of data sent in a streaming request or response.
// This is used in requests including InternalInvokeRequestStream.
message StreamPayload {
  // Data sent in the chunk.
  // The amount of data included in each chunk is up to the discretion of the sender, and can be empty.
  // Additionally, the amount of data doesn't need to be fixed and subsequent messages can send more, or less, data.
  // Receivers must not make assumptions about the number of bytes they'll receive in each chunk.
  bytes data = 1;

  // Sequence number. This is a counter that starts from 0 and increments by 1 on each chunk sent.
  uint64 seq = 2;
}

// StateItem represents state key, value, and additional options to save state.
message StateItem {
  // Required. The state key
  string key = 1;

  // Required. The state data for key
  bytes value = 2;

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

  // The metadata which will be passed to state store component.
  map<string,string> metadata = 4;

  // Options for concurrency and consistency to save the state.
  StateOptions options = 5;
}

// Etag represents a state item version
message Etag {
  // value sets the etag value
  string value = 1;
}

// StateOptions configures concurrency and consistency for state operations
message StateOptions {
  // Enum describing the supported concurrency for state.
  enum StateConcurrency {
    CONCURRENCY_UNSPECIFIED = 0;
    CONCURRENCY_FIRST_WRITE = 1;
    CONCURRENCY_LAST_WRITE = 2;
  }

  // Enum describing the supported consistency for state.
  enum StateConsistency {
    CONSISTENCY_UNSPECIFIED = 0;
    CONSISTENCY_EVENTUAL = 1;
    CONSISTENCY_STRONG = 2;
  }

  StateConcurrency concurrency = 1;
  StateConsistency consistency = 2;
}

// ConfigurationItem represents all the configuration with its name(key).
message ConfigurationItem {
  // Required. The value of configuration item.
  string value = 1;

  // Version is response only and cannot be fetched. Store is not expected to keep all versions available
  string version = 2;

  // the metadata which will be passed to/from configuration store component.
  map<string,string> metadata = 3;
}
