syntax = "proto3";

package devvit.plugin.payments.v1alpha;

import "devvit/payments/v1alpha/order.proto";
import "devvit/payments/v1alpha/product.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.snooguts.net/reddit/reddit-devplatform-monorepo/go-common/generated/protos/types/devvit/plugin/payments";
option java_package = "com.reddit.devvit.plugin.payments";

// PaymentsService provides a plugin for access to devvit's payment platform
// These functions can be called by your app to get product or order info
service PaymentsService {
  // get all (or filtered) products associated with your app
  rpc GetProducts(GetProductsRequest) returns (GetProductsResponse);
  // get all (or filtered) orders placed for your app
  rpc GetOrders(GetOrdersRequest) returns (GetOrdersResponse);
  // acknowledges an order has been fully delivered. This is used for asynchronous order fullfilment like pre-orders
  rpc AcknowledgeOrderDelivery(AcknowledgeOrderDeliveryRequest) returns (AcknowledgeOrderDeliveryResponse) {}
}

message GetProductsRequest {
  // if empty, all products will be returned
  repeated string skus = 1;
  // metadata to filter on. these values are combined via AND
  map<string, string> metadata = 2;
}

message GetProductsResponse {
  repeated devvit.payments.v1alpha.Product products = 1;
}

// GetOrderRequest allows for filtering which orders are returned
// all the parameters are optional. If none are provided, all orders are returned
message GetOrdersRequest {
  // start time filter
  // @deprecated - This currently does nothing. It may or may not be implemented in the future.
  google.protobuf.Timestamp start = 1;
  // end time filter
  // @experimental - This currently does nothing. It may or may not be implemented in the future.
  google.protobuf.Timestamp end = 2;
  // number of items to return
  int32 limit = 3;
  // unique identifier for the product
  // @experimental - This currently does nothing. It may or may not be implemented in the future.
  string sku = 4;
  // the t2 id of purchasing user
  // @experimental - This currently does nothing. It may or may not be implemented in the future.
  string buyer = 5;
  // the lifecycle status of the order
  // @experimental - This currently does nothing. It may or may not be implemented in the future.
  devvit.payments.v1alpha.OrderStatus status = 6;
  // metadata to filter on. these values are combined via AND
  // @experimental - This currently does nothing. It may or may not be implemented in the future.
  map<string, string> metadata = 7;
  // pagination cursor
  string cursor = 8;
}

message PageInfo {
  bool has_next_page = 1;
  string end_cursor = 2;
  bool has_previous_page = 3;
  string start_cursor = 4;
}

message GetOrdersResponse {
  repeated devvit.payments.v1alpha.Order orders = 1;
  PageInfo page_info = 2;
}

message AcknowledgeOrderDeliveryRequest {
  // the order that is being acknowledged
  string order_id = 1;
}

message AcknowledgeOrderDeliveryResponse {}
