syntax = "proto3";

package reddit.devvit.post.v1;

import "devvit/platform/v1/request_context.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/wrappers.proto";
import "reddit/devvit/app_permission/v1/app_permission.proto";
import "reddit/devvit/common/v1/error_message.proto";
import "reddit/devvit/common/v1/installation.proto";
import "reddit/devvit/useractions/v1/useractions.proto";

option go_package = "github.snooguts.net/reddit/devplatform-api/go/grpc/devvit/post/v1;post";

message BatchGetDevvitPostRequest {
  // List of t3_ post ids to get the DevvitPost for, eg ['t3_1g9qwle', 't3_1fdtrez']
  // Deprecated. Refer to the PostContext.Id field within RequestContext instead.
  repeated string post_ids = 1 [deprecated = true];
  // List of request contexts associated with each post.
  repeated .devvit.platform.v1.RequestContext request_contexts = 2;
}

message BatchGetDevvitPostResponse {
  // List of all DevvitPost responses, returned in the same order as the
  // requested post ids
  repeated DevvitPost posts = 1;
}

message DevvitPost {
  // Base64 encoded proto data representing the initial loading state of the post
  string initial_render = 1;
  // The installation corresponding to this Post
  reddit.devvit.common.v1.Installation installation = 2;
  // The fallback text that is displayed if the Post cannot be rendered
  string richtext_fallback = 3;
  // Error message if an error occurred while fetching the DevvitPost
  reddit.devvit.common.v1.ErrorMessage error = 4;
  // JWT providing authentication for client requests to the Webbit backend
  string webbit_token = 5;
  // URL base for all web view assets to be loaded from, beginning with "https://" and ending with "/".
  // Assets for this post can be found at {web_view_base_url}{asset_path}.
  string web_view_base_url = 6;
  // The entrypoint URL for the Post's initial webview, formatted like: https://{{slug}}-{{location}}-{{version}}-webview.devvit.net/{{path}}?token={{signed_request_context}}
  string entrypoint_url = 7;
  // JSON blob representing data on the Post, eg: { "devvit": { "splash": { "tagLine": "hello" } }, "riddle": "hello world" }
  google.protobuf.Struct post_data = 8;
  // The app permission granted by a user for the Post, if it exists.
  optional reddit.devvit.app_permission.v1.AppPermission app_permission = 9;
  // The list of entrypoints as defined in the app's devvit.json
  // Deprecated. Refer to entrypoints on WebViewClientData.AppConfig instead.
  repeated Entrypoint entrypoints = 10 [deprecated = true];
  // JSON blob representing the WebViewClientData for the Post, eg: { "appConfig": { "entrypoints": { "leaderboard": "https://{{slug}}-{{location}}-{{version}}-webview.devvit.net/leaderboard.html" } } }
  google.protobuf.Struct web_view_client_data = 11;
  // The signed RequestContext JWT string. This is different from webbit_token and contains different fields.
  string signed_request_context = 12;
  // The height of the Post entrypoint.
  // Deprecated: Use styles.height instead.
  EntrypointHeight entrypoint_height = 13 [deprecated = true];
  // The styles applied to the custom post.
  CustomPostStyles styles = 14;
}

message CustomPostStyles {
  // The default background color shown before an iframe is loaded. Must be in #RRGGBBAA (red, green, blue, alpha transparency) format with a leading hash.
  // The value is case-insensitive. Defaults to transparent (#00000000).
  string background_color = 1;
  // The dark mode background color shown before an iframe is loaded. Must be in #RRGGBBAA (red, green, blue, alpha transparency) format with a leading hash.
  // The value is case-insensitive. Defaults to transparent (#00000000).
  string background_color_dark = 2;
  // The integer height of the post representing pixels. Defaults to the value of 'tall'.
  // Devvit Gateway handles mapping 'tall' or 'regular' to the pixel height.
  int32 height_pixels = 3;
  // The height of the post. Defaults to 'tall'. This field is used to create or update the Post height.
  // Devvit Gateway maps 'tall' or 'regular' to the pixel height and returns both 'height_pixels' and 'height' to GQL.
  EntrypointHeight height = 4;
  // The URL of the preview image to show when being shared (e.x. OpenGraph's `og:image`).
  // Defaults to `https://i.redd.it/o0h58lzmax6a1.png`, which is the generic image used for any page that doesn't have a preview image.
  string share_image_url = 5;
}

// The height of the Post entrypoint. This is not expected to change often.
enum EntrypointHeight {
  HEIGHT_UNSPECIFIED = 0;
  REGULAR = 1;
  TALL = 2;
}

// Deprecated. In AppConfig, entrypoints are now represented as a map of <entryname, entrypointUrl>
message Entrypoint {
  option deprecated = true;
  // The name of the entrypoint, eg 'leaderboard'
  string name = 1;
  // The URL of the entrypoint. The URL does not include the context parameter and is formatted like: https://{{slug}}-{{location}}-{{version}}-webview.devvit.net/{{path}}
  string url = 2;
}

message CreateDevvitPostRequest {
  // The UUID of the app that created the Post.
  // Deprecated, use app_slug instead.
  string app_id = 1 [deprecated = true];
  // Base64 encoded proto data representing the initial loading state of the Post
  string initial_render = 2;
  // The UUID of the installation corresponding to the app which created the Post
  string installation_id = 3;
  // The t5_ subreddit where the Post is displayed
  string location = 4;
  // The fallback text that is displayed if the Post cannot be rendered
  string richtext_fallback = 5;
  // The title of the Post
  string title = 6;
  // The dependencies used by the app that created the Post
  repeated AppDependency app_dependencies = 7;
  // The IP address from the client request to create the Post. Required by post-service.
  string ip_address = 8;
  // The slug of the app that created the Post
  string app_slug = 9;
  // The t2_ author ID of the user to override creating the post as.
  // By default, the author of the post is set from the user ID in the current EdgeContext.
  // If this field is set, the request will only be allowed when invoked by privileged services.
  string author_id_override = 10;
  // User generated content on the Devvit post
  reddit.devvit.useractions.v1.UserGeneratedContent user_generated_content = 11;
  // Whether the post is NSFW
  bool is_nsfw = 12;
  // JSON blob representing data set on the Post, eg: { "devvit": { "splash": { "tagLine": "hello" } }, "riddle": "hello world" }
  google.protobuf.Struct post_data = 13;
  // The styles applied to the custom post. If not specified, Devvit Gateway will set default values.
  CustomPostStyles styles = 14;
}

message AppDependency {
  // The name of the package dependency, eg: "@devvit/protos"
  string package_name = 1;
  // The version of the dependency, eg: "0.11.4"
  string version = 2;
}

message CreateDevvitPostResponse {
  // The t3_ id of the created Post, eg t3_1qobwz7
  string id = 1;
  // Error message if an error occurred while creating the DevvitPost
  reddit.devvit.common.v1.ErrorMessage error = 2;
}

message UpdateDevvitPostRequest {
  // The t3_ id of the Post to update, eg t3_1qobwz7
  string id = 1;
  // The updated richtextFallback value of the Post
  // Deprecated, use text_fallback instead.
  string richtext_fallback = 2 [deprecated = true];
  // The IP address from the client request to update the Post. Required by post-service.
  string ip_address = 3;
  // JSON blob representing the updated Post data, eg: { "devvit": { "splash": { "tagLine": "hello" } }, "riddle": "hello world" }
  google.protobuf.Struct post_data = 4;
  // The updated textFallback value of the Post
  google.protobuf.StringValue text_fallback = 5;
}

message UpdateDevvitPostResponse {}

message UpdateDevvitPostRenderRequest {
  // The t3_ id of the Post to update, eg t3_1qobwz7
  string id = 1;
  // The updated base64 encoded Block proto representing the initial loading state of the post.
  // See devvit.ui.block_kit.v1beta.Block (https://github.snooguts.net/reddit/reddit-devplatform-monorepo/blob/main/packages/protos/schema/devvit/ui/block_kit/v1beta/block.proto)
  string initial_render = 2;
  // The IP address from the client request to update the Post. Required by post-service.
  string ip_address = 3;
}

message UpdateDevvitPostRenderResponse {}

message UpdateDevvitPostStylesRequest {
  // The t3_ id of the Post to update, eg t3_1qobwz7
  string id = 1;
  // The updated styles applied to the custom post.
  CustomPostStyles styles = 2;
}

message UpdateDevvitPostStylesResponse {
  // The t3_ id of the updated Post, eg t3_1qobwz7
  string id = 1;
  // Error message if an error occurred while updating the DevvitPost styles
  reddit.devvit.common.v1.ErrorMessage error = 2;
}

message CreateCustomPostSnapshotRequest {
  // ID of the snapshot containing the userId who created the snapshot and postId. Example: t2_mn8ek:t3_cj7zt.
  // Deprecated. Pass in user_id and post_id as separate fields instead.
  string snapshot_id = 1 [deprecated = true];
  // Base64 encoded proto data representing the initial loading state of the post. This is also known as the initial render.
  string render_config = 2;
  // Base64 encoded image data of the reported custom post.
  string image_data = 3;
  // t2_ ID of the user who reported the post, eg 't2_mn8ek'
  string user_id = 4;
  // t3_ ID of the post being reported, eg 't3_cj7zt'
  string post_id = 5;
  // The mime type of the image data. This is used by Devvit Gateway to upload the image data to MediaService.
  ImageDataMimeType mime_type = 6;
  // The IP address from the client request to create the snapshot.
  // For snapshot requests containing image_data, this is required by MediaService to call SubmitMedia.
  string ip_address = 7;
}

// Matches the values in the MediaService.MimeType enum.
// See: https://github.snooguts.net/reddit/media-api/blob/master/api/protos/reddit/foundation/media/v1/media.proto
enum ImageDataMimeType {
  GIF = 0;
  JPEG = 1;
  PNG = 2;
  WEBP = 3;
  MP4 = 4;
  QUICKTIME = 5;
}

message CreateCustomPostSnapshotResponse {
  // ID of the snapshot containing the userId who created the snapshot and postId. Example: t2_mn8ek:t3_cj7zt.
  // Deprecated. Use user_id and post_id instead.
  string snapshot_id = 1 [deprecated = true];
  // Base64 encoded proto data representing the initial loading state of the post. This is also known as the initial render.
  string render_config = 2;
  // Media ID of the image data uploaded to MediaService.
  string media_id = 3;
  // t2_ ID of the user who reported the post, eg 't2_mn8ek'
  string user_id = 4;
  // t3_ ID of the post being reported, eg 't3_cj7zt'
  string post_id = 5;
  // The CDN URL of the image that was uploaded to MediaService, eg: 'https://i.redd.it/0sv100oqsqhg1.png'
  string media_url = 6;
}

message GetCustomPostSnapshotRequest {
  // ID of the snapshot containing the userId who created the snapshot and postId. Example: t2_mn8ek:t3_cj7zt.
  // Deprecated. Pass in user_id and post_id as separate fields instead.
  string snapshot_id = 1 [deprecated = true];
  // t2_ ID of the user who reported the post, eg 't2_mn8ek'
  string user_id = 2;
  // t3_ ID of the post being reported, eg 't3_cj7zt'
  string post_id = 3;
}

message GetCustomPostSnapshotResponse {
  // Base64 encoded proto data representing the initial loading state of the post. This is also known as the initial render.
  string render_config = 1;
  // Media ID of the image data uploaded to MediaService.
  string media_id = 2;
  // The CDN URL of the image that was uploaded to MediaService, eg: 'https://i.redd.it/0sv100oqsqhg1.png'
  string media_url = 3;
}
