/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you 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";

option java_package = "org.apache.calcite.avatica.proto";

import "common.proto";

// Response that contains a result set.
message ResultSetResponse {
  string connection_id = 1;
  uint32 statement_id = 2;
  bool own_statement = 3;
  Signature signature = 4;
  Frame first_frame = 5;
  uint64 update_count = 6; // -1 for normal result sets, else this response contains a dummy result set
                                    // with no signature nor other data.
  RpcMetadata metadata = 7;
}

// Response to PrepareAndExecuteRequest
message ExecuteResponse {
  repeated ResultSetResponse results = 1;
  bool missing_statement = 2; // Did the request fail because of no-cached statement
  RpcMetadata metadata = 3;
}

// Response to PrepareRequest
message PrepareResponse {
  StatementHandle statement = 1;
  RpcMetadata metadata = 2;
}

// Response to FetchRequest
message FetchResponse {
  Frame frame = 1;
  bool missing_statement = 2; // Did the request fail because of no-cached statement
  bool missing_results = 3; // Did the request fail because of a cached-statement w/o ResultSet
  RpcMetadata metadata = 4;
}

// Response to CreateStatementRequest
message CreateStatementResponse {
  string connection_id = 1;
  uint32 statement_id = 2;
  RpcMetadata metadata = 3;
}

// Response to CloseStatementRequest
message CloseStatementResponse {
  RpcMetadata metadata = 1;
}

// Response to OpenConnectionRequest {
message OpenConnectionResponse {
  RpcMetadata metadata = 1;
}

// Response to CloseConnectionRequest {
message CloseConnectionResponse {
  RpcMetadata metadata = 1;
}

// Response to ConnectionSyncRequest
message ConnectionSyncResponse {
  ConnectionProperties conn_props = 1;
  RpcMetadata metadata = 2;
}

message DatabasePropertyElement {
  DatabaseProperty key = 1;
  TypedValue value = 2;
  RpcMetadata metadata = 3;
}

// Response for Meta#getDatabaseProperties()
message DatabasePropertyResponse {
  repeated DatabasePropertyElement props = 1;
  RpcMetadata metadata = 2;
}

// Send contextual information about some error over the wire from the server.
message ErrorResponse {
  repeated string exceptions = 1; // exception stacktraces, many for linked exceptions.
  bool has_exceptions = 7; // are there stacktraces contained?
  string error_message = 2; // human readable description
  Severity severity = 3;
  uint32 error_code = 4; // numeric identifier for error
  string sql_state = 5; // five-character standard-defined value
  RpcMetadata metadata = 6;
}

message SyncResultsResponse {
  bool missing_statement = 1; // Server doesn't have the statement with the ID from the request
  bool more_results = 2; // Should the client fetch() to get more results
  RpcMetadata metadata = 3;
}

// Generic metadata for the server to return with each response.
message RpcMetadata {
  string server_address = 1; // The host:port of the server
}

// Response to a commit request
message CommitResponse {

}

// Response to a rollback request
message RollbackResponse {

}

// Response to a batch update request
message ExecuteBatchResponse {
  string connection_id = 1;
  uint32 statement_id = 2;
  repeated uint64 update_counts = 3;
  bool missing_statement = 4; // Did the request fail because of no-cached statement
  RpcMetadata metadata = 5;
}
