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.
  EntrypointHeight entrypoint_height = 13;
}

// 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;
}

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
  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
  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
  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 CreateCustomPostSnapshotRequest {
  // ID of the snapshot containing the userId who created the snapshot and postId. Example: t2_mn8ek:t3_cj7zt.
  string snapshot_id = 1;
  // Base64 encoded proto data representing the initial loading state of the post. This is also known as the initial render.
  string render_config = 2;
}

message CreateCustomPostSnapshotResponse {
  // ID of the snapshot containing the userId who created the snapshot and postId. Example: t2_mn8ek:t3_cj7zt.
  string snapshot_id = 1;
  // Base64 encoded proto data representing the initial loading state of the post. This is also known as the initial render.
  string render_config = 2;
}

message GetCustomPostSnapshotRequest {
  // ID of the snapshot containing the userId who created the snapshot and postId. Example: t2_mn8ek:t3_cj7zt.
  string snapshot_id = 1;
}

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;
}
