syntax = "proto3";

package devvit.plugin.v1alpha.pushnotif;

import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";

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

// Request to queue a push notification for a user
message QueuePushNotificationRequest {
  // The Reddit user ID to send the notification to (e.g. "t2_abc123")
  string recipient_id = 1;

  // The title of the push notification
  string title = 2;

  // The body text of the push notification
  string body = 3;

  // The thing (comment or post) associated with this notification
  oneof thing {
    // The fullname of a comment (e.g., "t1_abc123")
    string comment = 4;

    // The fullname of a post (e.g., "t3_abc123")
    string post = 5;
  }
}

// Response from queuing a push notification
message QueuePushNotificationResponse {
  // Whether the notification was successfully queued
  bool success = 1;

  // Optional message providing additional context about the operation
  string message = 2;

  // Unix timestamp when the notification was queued
  int64 timestamp = 3;
}

// Request to queue multiple push notifications
message BulkQueuePushNotificationRequest {
  // The title of the push notification (mustache template supported)
  string title = 1;

  // The body text of the push notification (mustache template supported)
  string body = 2;

  // List of recipients to send the notification to
  repeated Recipient recipients = 5;
}

// Response from queuing multiple push notifications
message BulkQueuePushNotificationResponse {
  // Number of notifications successfully queued
  int32 success_count = 1;

  // Number of notifications that failed to queue
  int32 failure_count = 2;

  // Array of errors for notifications that failed to queue
  repeated PushNotificationError errors = 3;

  // Unix timestamp when the bulk operation was performed
  int64 timestamp = 4;
}

message Recipient {
  // The Reddit user ID to send the notification to (e.g. "t2_abc123")
  string user_id = 1;

  // The thing (comment or post) associated with this notification
  oneof thing {
    // The fullname of a comment (e.g., "t1_abc123")
    string comment = 2;

    // The fullname of a post (e.g., "t3_abc123")
    string post = 3;
  }

  // Additional data to include with the notification's mustache template
  google.protobuf.Struct data = 4;
}

message PushNotificationError {
  // The Reddit user ID for which the notification failed to queue (e.g. "t2_abc123")
  string user_id = 1;

  // Error message describing why the notification failed to queue
  string message = 2;
}

message OptInCurrentUserResponse {
  // Whether the user successfully opted in
  bool success = 1;

  // Optional message providing additional context about the operation
  string message = 2;
}

message OptOutCurrentUserResponse {
  // Whether the user successfully opted out
  bool success = 1;

  // Optional message providing additional context about the operation
  string message = 2;
}

message ListOptedInUsersRequest {
  // The maximum number of users to return. If this is greater than our max page size, it will be capped.
  optional int64 limit = 1;

  // Cursor to start listing AFTER. Interpreted as a timestamp in milliseconds.
  optional string after = 2;
}

message ListOptedInUsersResponse {
  // List of T2 user IDs who have opted in to receive push notifications (e.g. "t2_abc123", "t2_def456")
  repeated string user_ids = 1;

  // Next page cursor. Interpreted as a timestamp in milliseconds, pass back as `after`.
  optional string next = 2;
}

// Deprecated: Use the notifications service instead.
service PushNotif {
  option deprecated = true;

  // Deprecated: Use the notifications service instead.
  rpc QueuePushNotification(QueuePushNotificationRequest) returns (QueuePushNotificationResponse) {
    option deprecated = true;
  }

  // Deprecated: Use the notifications service instead.
  rpc BulkQueuePushNotification(BulkQueuePushNotificationRequest) returns (BulkQueuePushNotificationResponse) {
    option deprecated = true;
  }

  // Deprecated: Use the notifications service instead.
  rpc OptInCurrentUser(google.protobuf.Empty) returns (OptInCurrentUserResponse) {
    option deprecated = true;
  }

  // Deprecated: Use the notifications service instead.
  rpc OptOutCurrentUser(google.protobuf.Empty) returns (OptOutCurrentUserResponse) {
    option deprecated = true;
  }

  // Deprecated: Use the notifications service instead.
  rpc ListOptedInUsers(ListOptedInUsersRequest) returns (ListOptedInUsersResponse) {
    option deprecated = true;
  }
}
