syntax = "proto3";

package devvit.plugin.redditapi.wiki;

import "devvit/plugin/redditapi/common/common_msg.proto";
import "google/protobuf/wrappers.proto";

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

message GetWikiPagesRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
}

message GetWikiPagesResponse {
  // String value: "wikipagelisting"
  string kind = 1;
  // A list of wiki page names.
  repeated string data = 2;
}

message GetWikiPageRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
  // The revision ID (UUID) of the wiki page to retrieve. Setting this value will return the wiki page
  // version at that revision, and leaving it empty will return the latest version.
  google.protobuf.StringValue revision_id = 3;
}

message WikiPage {
  // The markdown content of the wiki page.
  string content_md = 1;
  // The HTML content of the wiki page.
  string content_html = 2;
  // The revision ID of the wiki page.
  string revision_id = 3;
  // The date of the wiki page's last revision.
  int64 revision_date = 4;
  // Whether the wiki page can be revised.
  bool may_revise = 5;
  // The reason for the wiki page's last revision.
  google.protobuf.StringValue reason = 6;
  // The user who last edited the wiki page.
  devvit.plugin.redditapi.common.WrappedUserObject revision_by = 7;
}

message GetWikiPageResponse {
  // String value: "wikipage"
  string kind = 1;
  // The data of the wiki page.
  WikiPage data = 2;
}

message EditWikiPageRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
  // The new content of the wiki page.
  string content = 3;
  // The reason for the edit.
  string reason = 4;
}

message HideWikiPageRevisionRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
  // The revision ID to hide.
  string revision = 3;
}

message HideWikiPageRevisionResponse {
  // Whether the revision was hidden.
  bool status = 1;
}

message GetWikiPageRevisionsRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
  // Revision ID
  // Return Revisions in the listing up to this Revision (non-inclusive)
  // Note: Do not use `before` and `after` in the same request
  google.protobuf.StringValue after = 3;
  // Revision ID
  // Return Revisions in the listing starting after this Revision (non-inclusive)
  // Note: Do not use `before` and `after` in the same request
  google.protobuf.StringValue before = 4;
  // The maximum number of revisions to return.
  google.protobuf.Int64Value limit = 5;
  // The number of items seen so far.
  // Use when fetching subsequent pages with `before` or `after`.
  google.protobuf.Int64Value count = 6;
  // (optional) Show all results regardless of user preferences
  google.protobuf.BoolValue show = 7;
  // (optional) expand subreddits
  google.protobuf.BoolValue sr_detail = 8;
}

message WikiPageRevision {
  // ID of the revision.
  string id = 1;
  // The name of the wiki page.
  string page = 2;
  // The date of the revision.
  int64 timestamp = 3;
  // The reason for the revision.
  string reason = 4;
  // Whether the revision is hidden.
  bool revision_hidden = 5;
  // The user who made the revision.
  devvit.plugin.redditapi.common.WrappedUserObject author = 6;
}

message WikiPageRevisionListing {
  message Data {
    // If present, use this as the `after` parameter when calling the same
    // API again to fetch the next page
    google.protobuf.StringValue after = 1;
    // If present, use this as the `before` parameter when calling the same
    // API again to fetch the previous page
    google.protobuf.StringValue before = 2;
    // Contents of the current page of the listing
    repeated WikiPageRevision children = 3;
    // Number of objects in `children`
    // Note: Only counts immediate entries in `children` and does not count
    //       nested objects such as comment trees
    google.protobuf.Int64Value dist = 4;
  }

  // String value: "Listing"
  string kind = 1;
  // The data of the wiki page revision listing.
  Data data = 2;
}

message GetWikiRevisionsRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // Revision ID
  // Return Revisions in the listing up to this Revision (non-inclusive)
  // Note: Do not use `before` and `after` in the same request
  google.protobuf.StringValue after = 2;
  // Revision ID
  // Return Revisions in the listing starting after this Revision (non-inclusive)
  // Note: Do not use `before` and `after` in the same request
  google.protobuf.StringValue before = 3;
  // The maximum number of revisions to return.
  google.protobuf.Int64Value limit = 4;
  // The number of items seen so far.
  // Use when fetching subsequent pages with `before` or `after`.
  google.protobuf.Int64Value count = 5;
  // (optional) Show all results regardless of user preferences
  google.protobuf.BoolValue show = 6;
  // (optional) expand subreddits
  google.protobuf.BoolValue sr_detail = 7;
}

message RevertWikiPageRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
  // The revision ID to revert to.
  string revision = 3;
}

message GetWikiPageSettingsRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
}

message WikiPageSettings {
  message Data {
    // The permission level required to edit the wiki page.
    int32 perm_level = 1;
    // The users who can edit the wiki page.
    repeated devvit.plugin.redditapi.common.WrappedUserObject editors = 2;
    // Whether the wiki page is listed.
    bool listed = 3;
  }

  // String value: "wikipagesettings"
  string kind = 1;
  // The data of the wiki page settings.
  Data data = 2;
}

message UpdateWikiPageSettingsRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
  // The permission level required to edit the wiki page.
  // 0: Use subreddit wiki permissions
  // 1: Only approved wiki contributors for this page may edit
  // 2: Only mods may edit and view
  int32 permlevel = 3;
  // Whether the wiki page is listed. "on" to list, empty string to hide.
  string listed = 4;
}

message AllowEditorRequest {
  // The subreddit omitting the r/ prefix.
  string subreddit = 1;
  // The name of the wiki page.
  string page = 2;
  // Either "add" or "del".
  string act = 3;
  // The username of the user to allow or deny.
  string username = 4;
}
