// Copyright 2022 Lightbend Inc.

syntax = "proto3";

package kalix;

import "google/protobuf/descriptor.proto";
import "kalix/json_schema.proto";

option go_package = "github.com/lightbend/kalix-go-sdk/kalix;kalix";
option java_multiple_files = true;
option java_outer_classname = "ViewsProto";
option java_package = "kalix";

// Views configuration for a gRPC method.
message View {
  oneof update_or_query {
    Update update = 1;
    Query query = 2;
  }
  message Update {
    // Indicates the name of the table that this processing method will persist
    // to, or that the query that is indexing will use.
    //
    // The return type of this call specifies the schema of the persisted value.
    // Any defined queries that select from this table will be selecting over this
    // schema.
    string table = 1;
    // Whether messages should automatically be persisted without further
    // processing. If false, received messages will be persisted at the key given
    // by the CloudEvents subject (that is, the entity key) without passing them
    // to the gRPC service call. That is, the user function does not need to
    // implement this service call.
    //
    // This flag is ignored if the method input parameter is different than the output,
    // since a transformation is necessary.
    //
    // For matching parameters (and methods marked with `eventing.in.handle_deletes = true`)
    // the default value (false) can be overridden for an additional message processing.
    //
    bool transform_updates = 2;
  }
  message Query {
    // A query that gets executed when this call is executed.
    //
    // This query is used to know how the view should be indexed.
    string query = 3;
    // Whether query results should be passed to the user function for further
    // processing before being returned to the client.
    //
    // By default (false), the user function does not process query results.
    bool transform_results = 4;
    // If enabled, initially, the normal query results are returned, but the stream
    // does not complete once the full result has been streamed, instead the stream
    // is kept open and updates and new entries added to the view are streamed.
    //
    // Can only be used for (stream) return values.
    bool stream_updates = 5;
  }
  // JSON input schemas, used for views that accept JSON events, view states, queries and query results
  JsonSchema json_schema = 6;
}
