syntax = "proto3";
package provenance.ledger.v1;

option go_package = "github.com/provenance-io/provenance/x/ledger/types";

option java_package        = "io.provenance.ledger.v1";
option java_multiple_files = true;

import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";
import "provenance/ledger/v1/ledger.proto";
import "provenance/ledger/v1/ledger_settlement.proto";

// Query defines the gRPC querier service for ledger module.
service Query {
  // LedgerClass returns the ledger class for a given ledger class id.
  rpc LedgerClass(QueryLedgerClassRequest) returns (QueryLedgerClassResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/class/{ledger_class_id}";
  }

  // LedgerClasses returns a paginated list of ledger classes.
  rpc LedgerClasses(QueryLedgerClassesRequest) returns (QueryLedgerClassesResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/class";
  }

  // LedgerClassEntryTypes returns the entry types for a given ledger class id.
  rpc LedgerClassEntryTypes(QueryLedgerClassEntryTypesRequest) returns (QueryLedgerClassEntryTypesResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/class/{ledger_class_id}/entry_types";
  }

  // LedgerClassStatusTypes returns the status types for a given ledger class id.
  rpc LedgerClassStatusTypes(QueryLedgerClassStatusTypesRequest) returns (QueryLedgerClassStatusTypesResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/class/{ledger_class_id}/status_types";
  }

  // LedgerClassBucketTypes returns the bucket types for a given ledger class id.
  rpc LedgerClassBucketTypes(QueryLedgerClassBucketTypesRequest) returns (QueryLedgerClassBucketTypesResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/class/{ledger_class_id}/bucket_types";
  }

  // Ledger returns the ledger for a given ledger key.
  rpc Ledger(QueryLedgerRequest) returns (QueryLedgerResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/config/{key.asset_class_id}/{key.nft_id}";
  }

  // Ledgers returns a paginated list of ledgers.
  rpc Ledgers(QueryLedgersRequest) returns (QueryLedgersResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/config";
  }

  // LedgerEntries returns the entries for a given ledger key.
  rpc LedgerEntries(QueryLedgerEntriesRequest) returns (QueryLedgerEntriesResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/entries/{key.asset_class_id}/{key.nft_id}";
  }

  // LedgerEntry returns a specific ledger entry for an NFT.
  rpc LedgerEntry(QueryLedgerEntryRequest) returns (QueryLedgerEntryResponse) {
    option (google.api.http).get =
        "/provenance/ledger/v1/ledger/{key.asset_class_id}/{key.nft_id}/entry/{correlation_id}";
  }

  // LedgerBalancesAsOf returns the balances for a specific NFT as of a given date.
  rpc LedgerBalancesAsOf(QueryLedgerBalancesAsOfRequest) returns (QueryLedgerBalancesAsOfResponse) {
    option (google.api.http).get =
        "/provenance/ledger/v1/ledger/{key.asset_class_id}/{key.nft_id}/balances/{as_of_date}";
  }

  // LedgerSettlements returns all settlements for a ledger.
  rpc LedgerSettlements(QueryLedgerSettlementsRequest) returns (QueryLedgerSettlementsResponse) {
    option (google.api.http).get = "/provenance/ledger/v1/ledger/{key.asset_class_id}/{key.nft_id}/settlements";
  }

  // LedgerSettlementsByCorrelationID returns settlements by correlation id.
  rpc LedgerSettlementsByCorrelationID(QueryLedgerSettlementsByCorrelationIDRequest)
      returns (QueryLedgerSettlementsByCorrelationIDResponse) {
    option (google.api.http).get =
        "/provenance/ledger/v1/ledger/{key.asset_class_id}/{key.nft_id}/settlements/{correlation_id}";
  }
}

// QueryLedgerClassRequest
message QueryLedgerClassRequest {
  string ledger_class_id = 1;
}

// QueryLedgerClassResponse
message QueryLedgerClassResponse {
  LedgerClass ledger_class = 1;
}

// QueryLedgerClassesRequest
message QueryLedgerClassesRequest {
  // pagination is an optional pagination for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 99;
}

// QueryLedgerClassesResponse
message QueryLedgerClassesResponse {
  // List of ledger classes.
  repeated LedgerClass ledger_classes = 1;

  // pagination is the pagination details for this response.
  cosmos.base.query.v1beta1.PageResponse pagination = 99;
}

// QueryLedgerClassEntryTypesRequest
message QueryLedgerClassEntryTypesRequest {
  string ledger_class_id = 1;
}

// QueryLedgerClassEntryTypesResponse
message QueryLedgerClassEntryTypesResponse {
  repeated LedgerClassEntryType entry_types = 1;
}

// QueryLedgerClassStatusTypesRequest
message QueryLedgerClassStatusTypesRequest {
  string ledger_class_id = 1;
}

// QueryLedgerClassStatusTypesResponse
message QueryLedgerClassStatusTypesResponse {
  repeated LedgerClassStatusType status_types = 1;
}

// QueryLedgerClassBucketTypesRequest
message QueryLedgerClassBucketTypesRequest {
  string ledger_class_id = 1;
}

// QueryLedgerClassBucketTypesResponse
message QueryLedgerClassBucketTypesResponse {
  repeated LedgerClassBucketType bucket_types = 1;
}

// QueryLedgerRequest
message QueryLedgerRequest {
  // The ledger key identifying the ledger to query.
  LedgerKey key = 1;
}

// QueryLedgerResponse
message QueryLedgerResponse {
  // The ledger data.
  Ledger ledger = 1;
}

// QueryLedgersRequest
message QueryLedgersRequest {
  // pagination is an  pagination for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 99;
}

// QueryLedgersResponse
message QueryLedgersResponse {
  // List of ledgers.
  repeated Ledger ledgers = 1;

  // pagination is the pagination details for this response.
  cosmos.base.query.v1beta1.PageResponse pagination = 99;
}

// QueryLedgerEntriesRequest
message QueryLedgerEntriesRequest {
  // The ledger key identifying the ledger to query entries for.
  LedgerKey key = 1;
}

// QueryLedgerEntriesResponse
message QueryLedgerEntriesResponse {
  // The ledger entries.
  repeated LedgerEntry entries = 1;
}

// QueryLedgerEntryRequest
message QueryLedgerEntryRequest {
  // The ledger key identifying the ledger.
  LedgerKey key = 1;
  // The correlation ID of the entry to query (free-form string up to 50 characters).
  string correlation_id = 2;
}

// QueryLedgerEntryResponse
message QueryLedgerEntryResponse {
  // The ledger entry.
  LedgerEntry entry = 1;
}

// QueryLedgerBalancesAsOfRequest
message QueryLedgerBalancesAsOfRequest {
  LedgerKey key = 1;

  // The date to query balances as of (format: YYYY-MM-DD).
  string as_of_date = 2;
}

// QueryLedgerBalancesAsOfResponse
message QueryLedgerBalancesAsOfResponse {
  // BucketBalances represents the current balances for principal, interest, and other amounts.
  repeated BucketBalance bucket_balances = 1;
}

// QueryLedgerSettlementsRequest
message QueryLedgerSettlementsRequest {
  LedgerKey key = 1;
}

// QueryLedgerSettlementsResponse
message QueryLedgerSettlementsResponse {
  repeated SettlementInstruction settlements = 1;
}

// QueryLedgerSettlementsByCorrelationIDRequest
message QueryLedgerSettlementsByCorrelationIDRequest {
  LedgerKey key = 1;
  // The correlation ID to query settlements for.
  string correlation_id = 2;
}

// QueryLedgerSettlementsByCorrelationIDResponse
message QueryLedgerSettlementsByCorrelationIDResponse {
  repeated SettlementInstruction settlements = 1;
}