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

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

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

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

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

  // Members queries all members.
  rpc Members(QueryMembersRequest) returns (QueryMembersResponse) {
    option (google.api.http).get = "/bandtss/v1beta1/members";
  }

  // Member queries the member information of the given address.
  rpc Member(QueryMemberRequest) returns (QueryMemberResponse) {
    option (google.api.http).get = "/bandtss/v1beta1/members/{address}";
  }

  // CurrentGroup queries the current group information.
  rpc CurrentGroup(QueryCurrentGroupRequest) returns (QueryCurrentGroupResponse) {
    option (google.api.http).get = "/bandtss/v1beta1/current_group";
  }

  // IncomingGroup queries the incoming group information.
  rpc IncomingGroup(QueryIncomingGroupRequest) returns (QueryIncomingGroupResponse) {
    option (google.api.http).get = "/bandtss/v1beta1/incoming_group";
  }

  // Signing queries the signing result of the given signing request ID.
  rpc Signing(QuerySigningRequest) returns (QuerySigningResponse) {
    option (google.api.http).get = "/bandtss/v1beta1/signings/{signing_id}";
  }

  // GroupTransition queries the group transition information.
  rpc GroupTransition(QueryGroupTransitionRequest) returns (QueryGroupTransitionResponse) {
    option (google.api.http).get = "/bandtss/v1beta1/group_transition";
  }

  // Params queries parameters of bandtss module
  rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
    option (google.api.http).get = "/bandtss/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 {
  // signing_count is total number of signing request submitted to bandtss module
  uint64 signing_count = 1;
}

// QueryMembersRequest is the request type for the Query/Members RPC method.
message QueryMembersRequest {
  // status define type of filter on member's status.
  MemberStatusFilter status = 1;
  // is_incoming_group is a flag to indicate whether user query members in the incoming group
  // or the current group.
  bool is_incoming_group = 2;
  // pagination defines pagination settings for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryMembersResponse is the response type for the Query/Members RPC method.
message QueryMembersResponse {
  // members are those individuals who correspond to the provided is_active status.
  repeated Member members = 1;
  // pagination defines the pagination in the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryMemberRequest is the request type for the Query/Member RPC method.
message QueryMemberRequest {
  // address is the member address.
  string address = 1;
}

// QueryMemberResponse is the response type for the Query/Member RPC method.
message QueryMemberResponse {
  // current_group_member is the member detail.
  Member current_group_member = 1 [(gogoproto.nullable) = false];
  // incoming_group_member is the member detail.
  Member incoming_group_member = 2 [(gogoproto.nullable) = false];
}

// QueryCurrentGroupRequest is the request type for the Query/CurrentGroup RPC method.
message QueryCurrentGroupRequest {}

// QueryCurrentGroupResponse is the response type for the Query/CurrentGroup RPC method.
message QueryCurrentGroupResponse {
  // group_id is the ID of the current group.
  uint64 group_id = 1
      [(gogoproto.customname) = "GroupID", (gogoproto.casttype) = "github.com/bandprotocol/chain/v3/pkg/tss.GroupID"];
  // size is the number of members in the group.
  uint64 size = 2;
  // threshold is the minimum number of members needed to generate a valid signature.
  uint64 threshold = 3;
  // pub_key is the public key generated by the group.
  bytes pub_key = 4 [(gogoproto.casttype) = "github.com/bandprotocol/chain/v3/pkg/tss.Point"];
  // status is the status of the current group.
  band.tss.v1beta1.GroupStatus status = 5;
  // active_time is the timestamp at which the group becomes the current group of the module.
  google.protobuf.Timestamp active_time = 6 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}

// QueryIncomingGroupRequest is the request type for the Query/IncomingGroup RPC method.
message QueryIncomingGroupRequest {}

// QueryIncomingGroupResponse is the response type for the Query/IncomingGroup RPC method.
message QueryIncomingGroupResponse {
  // group_id is the ID of the incoming group.
  uint64 group_id = 1
      [(gogoproto.customname) = "GroupID", (gogoproto.casttype) = "github.com/bandprotocol/chain/v3/pkg/tss.GroupID"];
  // size is the number of members in the group.
  uint64 size = 2;
  // threshold is the minimum number of members needed to generate a valid signature.
  uint64 threshold = 3;
  // pub_key is the public key generated by the group.
  bytes pub_key = 4 [(gogoproto.casttype) = "github.com/bandprotocol/chain/v3/pkg/tss.Point"];
  // status is the status of the incoming group.
  band.tss.v1beta1.GroupStatus status = 5;
}

// 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 {
  // fee_per_signer is the tokens that will be paid per signer for this bandtss signing.
  repeated cosmos.base.v1beta1.Coin fee_per_signer = 1
      [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
  // requester is the address of requester who paid for bandtss signing.
  string requester = 2;
  // current_group_signing_result is the signing result from the current group.
  band.tss.v1beta1.SigningResult current_group_signing_result = 3;
  // incoming_group_signing_result is the signing result from the incoming group.
  band.tss.v1beta1.SigningResult incoming_group_signing_result = 4;
}

// QueryGroupTransitionRequest is the request type for the Query/GroupTransition RPC method.
message QueryGroupTransitionRequest {}

// QueryGroupTransitionResponse is the response type for the Query/GroupTransition RPC method.
message QueryGroupTransitionResponse {
  // group_transition is the group transition information.
  GroupTransition group_transition = 1;
}

// MemberStatusFilter defines the query options for filtering members by their active status.
enum MemberStatusFilter {
  option (gogoproto.goproto_enum_prefix) = false;

  // MEMBER_STATUS_FILTER_UNSPECIFIED defines a filter for unspecified active status.
  MEMBER_STATUS_FILTER_UNSPECIFIED = 0;
  // MEMBER_STATUS_FILTER_ACTIVE defines a filter for active status.
  MEMBER_STATUS_FILTER_ACTIVE = 1;
  // MEMBER_STATUS_FILTER_INACTIVE defines a filter for inactive status.
  MEMBER_STATUS_FILTER_INACTIVE = 2;
}

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

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