syntax = "proto3";

package logic.v1beta3;

import "cosmos/query/v1/query.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "logic/v1beta3/params.proto";
import "logic/v1beta3/types.proto";

option go_package = "github.com/axone-protocol/axoned/x/logic/types";

// QueryService defines the gRPC querier service.
service QueryService {
  // Params queries all parameters for the logic module.
  rpc Params(QueryServiceParamsRequest) returns (QueryServiceParamsResponse) {
    option (cosmos.query.v1.module_query_safe) = true;
    option (google.api.http).get = "/axone-protocol/axoned/logic/params";
  }

  // Ask executes a logic query and returns the solutions found.
  // Since the query is without any side-effect, the query is not executed in the context of a transaction and no fee
  // is charged for this, but the execution is constrained by the current limits configured in the module.
  rpc Ask(QueryServiceAskRequest) returns (QueryServiceAskResponse) {
    option (cosmos.query.v1.module_query_safe) = true;
    option (google.api.http).get = "/axone-protocol/axoned/logic/ask";
  }
}

// QueryServiceParamsRequest is request type for the QueryService/Params RPC method.
message QueryServiceParamsRequest {}

// QueryServiceParamsResponse is response type for the QueryService/Params RPC method.
message QueryServiceParamsResponse {
  // params holds all the parameters of this module.
  Params params = 1 [
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"params\",omitempty"
  ];
}

// QueryServiceAskRequest is request type for the QueryService/Ask RPC method.
message QueryServiceAskRequest {
  option (gogoproto.goproto_stringer) = true;

  // program is the logic program to be queried.
  string program = 1 [(gogoproto.moretags) = "yaml:\"program\",omitempty"];
  // query is the query string to be executed.
  string query = 2 [(gogoproto.moretags) = "yaml:\"query\",omitempty"];
  // limit specifies the maximum number of solutions to be returned. This field is governed by
  // max_result_count, which defines the upper limit of results that may be requested per query.
  // If this field is not explicitly set, a default value of 1 is applied.
  uint64 limit = 3 [(gogoproto.moretags) = "yaml:\"limit\",omitempty"];
}

// QueryServiceAskResponse is response type for the QueryService/Ask RPC method.
message QueryServiceAskResponse {
  option (gogoproto.goproto_stringer) = true;

  // height is the block height at which the query was executed.
  uint64 height = 1 [(gogoproto.moretags) = "yaml:\"height\",omitempty"];
  // gas_used is the amount of gas used to execute the query.
  uint64 gas_used = 2 [(gogoproto.moretags) = "yaml:\"gas_used\",omitempty"];
  // answer is the answer to the query.
  Answer answer = 3 [(gogoproto.moretags) = "yaml:\"answer\",omitempty"];
  // user_output is the output of the query execution, if any.
  // the length of the output is limited by the max_query_output_size parameter.
  string user_output = 4 [(gogoproto.moretags) = "yaml:\"user_output\",omitempty"];
}
