syntax = "proto3";
package band.tss.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";

import "band/tss/v1beta1/tss.proto";
import "band/tss/v1beta1/genesis.proto";

option go_package = "github.com/bandprotocol/chain/v3/x/tss/types";

// Query defines the gRPC querier service.
service Query {
  // Counts queries the number of existing groups and signing.
  rpc Counts(QueryCountsRequest) returns (QueryCountsResponse) {
    option (google.api.http).get = "/tss/v1beta1/counts";
  }

  // Groups queries groups details.
  rpc Groups(QueryGroupsRequest) returns (QueryGroupsResponse) {
    option (google.api.http).get = "/tss/v1beta1/groups";
  }

  // Group queries group details from the given id.
  rpc Group(QueryGroupRequest) returns (QueryGroupResponse) {
    option (google.api.http).get = "/tss/v1beta1/groups/{group_id}";
  }

  // Members queries all members in this group.
  rpc Members(QueryMembersRequest) returns (QueryMembersResponse) {
    option (google.api.http).get = "/tss/v1beta1/groups/{group_id}/members";
  }

  // IsGrantee queries whether granter grants the grantee.
  rpc IsGrantee(QueryIsGranteeRequest) returns (QueryIsGranteeResponse) {
    option (google.api.http).get = "/tss/v1beta1/is_grantee/{granter}/{grantee}";
  }

  // DE queries all de for this address.
  rpc DE(QueryDERequest) returns (QueryDEResponse) {
    option (google.api.http).get = "/tss/v1beta1/de_list/{address}";
  }

  // PendingGroups queries all pending groups that waits the given address to submit a message.
  rpc PendingGroups(QueryPendingGroupsRequest) returns (QueryPendingGroupsResponse) {
    option (google.api.http).get = "/tss/v1beta1/pending_groups/{address}";
  }

  // PendingSignings queries all pending requests that waits the given address to sign a message.
  rpc PendingSignings(QueryPendingSigningsRequest) returns (QueryPendingSigningsResponse) {
    option (google.api.http).get = "/tss/v1beta1/pending_signings/{address}";
  }

  // Signing queries signing details from the given id.
  rpc Signing(QuerySigningRequest) returns (QuerySigningResponse) {
    option (google.api.http).get = "/tss/v1beta1/signings/{signing_id}";
  }

  // Signings queries signings details.
  rpc Signings(QuerySigningsRequest) returns (QuerySigningsResponse) {
    option (google.api.http).get = "/tss/v1beta1/signings";
  }

  // Params returns all parameters of the module.
  rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
    option (google.api.http).get = "/tss/v1beta1/params";
  }
}

// QueryCountsRequest is request type for the Query/Count RPC method.
message QueryCountsRequest {}

// QueryCountsResponse is response type for the Query/Count RPC method.
message QueryCountsResponse {
  // group_count is total number of group available on the chain
  uint64 group_count = 1;
  // signing_count is total number of signing request submitted to the chain
  uint64 signing_count = 2;
}

// QueryGroupRequest is the request type for the Query/Group RPC method
message QueryGroupRequest {
  // group_id defines the unique id of the group.
  uint64 group_id = 1;
}

// QueryGroupResponse is the response type for the Query/Group RPC method
message QueryGroupResponse {
  // group_result is the result of the group.
  GroupResult group_result = 1 [(gogoproto.nullable) = false];
}

// QueryGroupsRequest is the request type for the Query/Groups RPC method
message QueryGroupsRequest {
  // pagination defines pagination settings for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryGroupsResponse is the response type for the Query/Group RPC method
message QueryGroupsResponse {
  // groups is the list of groups.
  repeated GroupResult groups = 1;
  // pagination defines an pagination for the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryMembersRequest is the request type for the Query/Members RPC method
message QueryMembersRequest {
  // group_id defines the unique id of the group.
  uint64 group_id = 1;
}

// QueryMembersResponse is the response type for the Query/Members RPC method
message QueryMembersResponse {
  // members are member list of the group
  repeated Member members = 1 [(gogoproto.nullable) = false];
}

// QueryIsGranteeRequest is request type for the Query/IsGrantee RPC method.
message QueryIsGranteeRequest {
  // granter is a granter address
  string granter = 1;
  // grantee is a grantee address
  string grantee = 2;
}

// QueryIsGranteeResponse is response type for the Query/IsGrantee RPC method.
message QueryIsGranteeResponse {
  // is_grantee is true if this account has been granted by granter
  bool is_grantee = 1;
}

// QueryDERequest is the request type for the Query/DE RPC method.
message QueryDERequest {
  // address is the address for the request.
  string address = 1;
  // pagination defines pagination settings for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryDEResponse is the response type for the Query/DE RPC method.
message QueryDEResponse {
  // des is a list of DEs.
  repeated DE des = 1 [(gogoproto.customname) = "DEs", (gogoproto.nullable) = false];
  // pagination defines an pagination for the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryPendingGroupsRequest is the request type for the Query/PendingGroups RPC method.
message QueryPendingGroupsRequest {
  // address is the address of the member.
  string address = 1;
}

// QueryPendingGroupsResponse is the response type for the Query/PendingGroups RPC method.
message QueryPendingGroupsResponse {
  // pending_groups is a list of pending groups.
  repeated uint64 pending_groups = 1;
}

// QueryPendingSigningsRequest is the request type for the Query/PendingSignings RPC method.
message QueryPendingSigningsRequest {
  // address is the address of the member.
  string address = 1;
}

// QueryPendingSigningsResponse is the response type for the Query/PendingSignings RPC method.
message QueryPendingSigningsResponse {
  // pending_signings is a list of pending signings.
  repeated uint64 pending_signings = 1 [(gogoproto.casttype) = "github.com/bandprotocol/chain/v3/pkg/tss.SigningID"];
}

// QuerySigningRequest is the request type for the Query/Signing RPC method.
message QuerySigningRequest {
  // signing_id is the ID of the signing request.
  uint64 signing_id = 1;
}

// QuerySigningResponse is the response type for the Query/Signing RPC method.
message QuerySigningResponse {
  // signing_result is the result of the signing.
  SigningResult signing_result = 1 [(gogoproto.nullable) = false];
}

// QuerySigningsRequest is the request type for the Query/Signings RPC method.
message QuerySigningsRequest {
  // pagination defines pagination settings for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QuerySigningsResponse is the response type for the Query/Signings RPC method.
message QuerySigningsResponse {
  // signing_results is a list of signing results.
  repeated SigningResult signing_results = 1;
  // pagination defines an pagination for the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
  // params are the parameters of the module.
  Params params = 1 [(gogoproto.nullable) = false];
}
