syntax = "proto3";

package devvit.plugin.redditapi.newmodmail;

import "google/protobuf/any.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.newmodmail";

// Shared Objects
message ConversationData {
  message ObjId {
    // Id of an object (e.g. message ID or modAction ID)
    google.protobuf.StringValue id = 1;
    // Property name of the object collection (e.g. 'messages' or 'modActions')
    google.protobuf.StringValue key = 2;
  }

  message Owner {
    // Subreddit display name
    google.protobuf.StringValue display_name = 1;
    // always 'subreddit'
    google.protobuf.StringValue type = 2;
    // Subreddit id
    google.protobuf.StringValue id = 3;
  }

  // Is the conversation automatically generated e.g. from automod, u/reddit
  google.protobuf.BoolValue is_auto = 1;
  // Participant. Is absent for mod discussions
  Participant participant = 2;
  // List of object ids (denormalized). E.g. [{id: 'qwer42', key: 'messages'}, {id: 'abcd33', key: 'modActions'}]
  repeated ObjId obj_ids = 3;
  // NOTE: is_repliable will always be true currently (at the time of writing this comment)
  google.protobuf.BoolValue is_repliable = 4;
  // The last datetime a user made any interaction with the conversation
  google.protobuf.StringValue last_user_update = 5;
  // Is the conversation internal (i.e. mod only)
  google.protobuf.BoolValue is_internal = 6;
  // The last datetime a mod from the owning subreddit made any interaction with the conversation.
  // (Note that if this is a subreddit to subreddit conversation, the mods of
  // the participant subreddit are irrelevant and do not affect this field.)
  google.protobuf.StringValue last_mod_update = 7;
  repeated Participant authors = 8;
  // The last time the conversation was updated (includes actions)
  google.protobuf.StringValue last_updated = 9;
  // Id of the first corresponding message in the legacy message system
  google.protobuf.StringValue legacy_first_message_id = 10;
  google.protobuf.Int32Value state = 11;
  // Type of conversation:
  // - `internal` (mod discussion)
  // - `sr_user` (between a subreddit and user)
  // - `sr_sr` (between two subreddits)
  google.protobuf.StringValue conversation_type = 12;
  // The datetime of the last unread message within this conversation for the current viewer.
  google.protobuf.StringValue last_unread = 13;
  // The subreddit that owns the conversation.
  Owner owner = 14;
  // Suject of the conversation
  google.protobuf.StringValue subject = 15;
  // Conversation ID
  google.protobuf.StringValue id = 16;
  // Is the conversation highlighted
  google.protobuf.BoolValue is_highlighted = 17;
  // Number of messages (not actions) in the conversation
  google.protobuf.Int64Value num_messages = 18;

  // from createconversationmessageresponse
  map<string, ModActionData> mod_actions = 19;
}

message MessageData {
  google.protobuf.StringValue body = 1;
  Participant author = 2;
  google.protobuf.BoolValue is_internal = 3;
  google.protobuf.StringValue date = 4;
  google.protobuf.StringValue body_markdown = 5;
  google.protobuf.StringValue id = 6;
  google.protobuf.StringValue participating_as = 7;
}

message ConversationUserData {
  message CommentData {
    google.protobuf.StringValue comment = 1;
    google.protobuf.StringValue date = 2;
    google.protobuf.StringValue permalink = 3;
    google.protobuf.StringValue title = 4;
  }
  message MuteStatus {
    google.protobuf.Int64Value mute_count = 1;
    google.protobuf.BoolValue is_muted = 2;
    google.protobuf.StringValue end_date = 3;
    google.protobuf.StringValue reason = 4;
  }
  message BanStatus {
    google.protobuf.BoolValue is_banned = 1;
    google.protobuf.BoolValue is_permanent = 2;
    google.protobuf.StringValue end_date = 3;
    google.protobuf.StringValue reason = 4;
  }
  message ApproveStatus {
    google.protobuf.BoolValue is_approved = 1;
  }
  message PostData {
    google.protobuf.StringValue date = 1;
    google.protobuf.StringValue permalink = 2;
    google.protobuf.StringValue title = 3;
  }
  message ConvoData {
    google.protobuf.StringValue date = 1;
    google.protobuf.StringValue permalink = 2;
    google.protobuf.StringValue id = 3;
    google.protobuf.StringValue subject = 4;
  }

  map<string, CommentData> recent_comments = 1;
  MuteStatus mute_status = 2;
  google.protobuf.StringValue name = 3;
  google.protobuf.StringValue created = 4;
  BanStatus ban_status = 5;
  google.protobuf.BoolValue is_suspended = 6;
  ApproveStatus approve_status = 7;
  google.protobuf.BoolValue is_shadow_banned = 8;
  map<string, PostData> recent_posts = 9;
  map<string, ConvoData> recent_convos = 10;
  google.protobuf.StringValue id = 11;
}

message Participant {
  google.protobuf.BoolValue is_mod = 1;
  google.protobuf.BoolValue is_admin = 2;
  google.protobuf.StringValue name = 3;
  google.protobuf.BoolValue is_op = 4;
  google.protobuf.BoolValue is_participant = 5;
  google.protobuf.BoolValue is_approved = 6;
  google.protobuf.BoolValue is_hidden = 7;
  google.protobuf.Int64Value id = 8;
  google.protobuf.BoolValue is_deleted = 9;
}

message ModActionData {
  message ModActionAuthor {
    google.protobuf.BoolValue is_mod = 1;
    google.protobuf.BoolValue is_admin = 2;
    google.protobuf.StringValue name = 3;
    google.protobuf.BoolValue is_hidden = 4;
    google.protobuf.Int64Value id = 5;
    google.protobuf.BoolValue is_deleted = 6;
  }

  google.protobuf.StringValue date = 1;
  google.protobuf.Int32Value action_type_id = 2;
  google.protobuf.StringValue id = 3;
  ModActionAuthor author = 4;
}

// Requests
message BulkReadConversationsRequest {
  // comma-delimited list of subreddit names (e.g. 'pics,worldnews'
  string entity = 1;
  // one of (all, appeals, notifications, inbox, filtered, inprogress, mod, archived, default,
  // highlighted, join_requests, new)
  string state = 2;
}

message GetConversationsRequest {
  // id36 of a modmail
  google.protobuf.StringValue after = 1;
  // comma-delimited list of subreddit names
  google.protobuf.StringValue entity = 2;
  // an integer between 1 and 100 (default: 25)
  google.protobuf.Int32Value limit = 3;
  // one of (recent, mod, user, unread)
  google.protobuf.StringValue sort = 4;
  // one of (all, appeals, notifications, inbox, filtered, inprogress, mod, archived, default,
  // highlighted, join_requests, new)
  google.protobuf.StringValue state = 5;
}

message CreateConversationRequest {
  // raw markdown text
  string body = 1;
  // is author hidden?
  bool is_author_hidden = 2;
  // subreddit name
  string sr_name = 3;
  // subject of the conversation. max 100 characters.
  string subject = 4;
  // a user (e.g. u/username), a subreddit (e.g. r/subreddit) or null
  google.protobuf.StringValue to = 5;
}

message GetConversationRequest {
  // id36 of a modmail conversation id
  string conversation_id = 1;
  // mark read?
  bool mark_read = 2;
}

message CreateConversationMessageRequest {
  // markdown text
  string body = 1;
  bool is_author_hidden = 2;
  bool is_internal = 3;
  // id36 of a modmail conversation id
  string conversation_id = 4;
}

message BasicConversationRequest {
  // id36 of a modmail conversation id
  string conversation_id = 1;
}

message BasicConversationsRequest {
  // comma seperated list of id36 of a modmail conversation ids
  string conversation_ids = 1;
}

message MuteConversationRequest {
  // id36 of a modmail conversation id
  string conversation_id = 1;
  // how long? one of (72, 168, 672)
  int32 num_hours = 2;
}

message TempBanRequest {
  // id36 of a modmail conversation id
  string conversation_id = 1;
  // duration in days, max 999
  int32 duration = 2;
}

// Responses
message BulkReadConversationsResponse {
  repeated google.protobuf.StringValue conversation_ids = 1;
}

message GetConversationsResponse {
  map<string, ConversationData> conversations = 1;
  map<string, MessageData> messages = 2;
  google.protobuf.StringValue viewer_id = 3;
  repeated google.protobuf.StringValue conversation_ids = 4;
}

message CreateConversationResponse {
  ConversationData conversation = 1;
  map<string, MessageData> messages = 2;
  map<string, ModActionData> mod_actions = 3;

  // error case
  repeated google.protobuf.StringValue fields = 4;
  google.protobuf.StringValue reason = 5;
  google.protobuf.StringValue message = 6;
  google.protobuf.StringValue explanation = 7;

  ConversationUserData user = 8;
}

message GetConversationResponse {
  ConversationData conversation = 1;
  map<string, MessageData> messages = 2;
  map<string, ModActionData> mod_actions = 3;
  google.protobuf.Any participant_subreddit = 4;
  ConversationUserData user = 5;
}

message CreateConversationMessageResponse {
  ConversationData conversation = 1;
  map<string, MessageData> messages = 2;
  ConversationUserData user = 3;
}

message ApproveConversationResponse {
  ConversationData conversations = 1;
  map<string, MessageData> messages = 2;
  ConversationUserData user = 3;
  map<string, ModActionData> mod_actions = 4;

  // error case
  repeated google.protobuf.StringValue fields = 5;
  google.protobuf.StringValue reason = 6;
  google.protobuf.StringValue message = 7;
  google.protobuf.StringValue explanation = 8;
}

message ArchiveConversationResponse {
  // @deprecated use `conversation`
  ConversationData conversations = 1;
  map<string, MessageData> messages = 2;
  map<string, ModActionData> mod_actions = 3;
  ConversationData conversation = 4;
}

message HighlightConversationResponse {
  // @deprecated use `conversation`
  ConversationData conversations = 1;
  map<string, MessageData> messages = 2;
  map<string, ModActionData> mod_actions = 3;
  ConversationData conversation = 4;
}

message MuteConversationResponse {
  ConversationData conversations = 1;
  map<string, MessageData> messages = 2;
  ConversationUserData user = 3;
  map<string, ModActionData> mod_actions = 4;
}

message TempBanResponse {
  ConversationData conversations = 1;
  map<string, MessageData> messages = 2;
  ConversationUserData user = 3;
  map<string, ModActionData> mod_actions = 4;

  // error case
  repeated google.protobuf.StringValue fields = 5;
  google.protobuf.StringValue reason = 6;
  google.protobuf.StringValue message = 7;
}

message SubredditsResponse {
  message SubredditData {
    google.protobuf.StringValue community_icon = 1;
    google.protobuf.StringValue key_color = 2;
    google.protobuf.StringValue display_name = 3;
    google.protobuf.StringValue name = 4;
    google.protobuf.Int32Value subscribers = 5;
    google.protobuf.StringValue primary_color = 6;
    google.protobuf.StringValue id = 7;
    google.protobuf.StringValue last_updated = 8;
    google.protobuf.StringValue icon = 9;
  }

  map<string, SubredditData> subreddits = 1;
}

message UnreadCountResponse {
  google.protobuf.Int32Value archived = 1;
  google.protobuf.Int32Value appeals = 2;
  google.protobuf.Int32Value highlighted = 3;
  google.protobuf.Int32Value notifications = 4;
  google.protobuf.Int32Value join_requests = 5;
  google.protobuf.Int32Value filtered = 6;
  google.protobuf.Int32Value new = 7;
  google.protobuf.Int32Value inprogress = 8;
  google.protobuf.Int32Value mod = 9;
}

message CreateModmailConversationRequest {
  // Subject of the conversation, eg: "Welcome to the subreddit!"
  string subject = 1;
  // Body of the conversation. Supports markdown formatting. Eg: "**Hello** \n Welcome to the subreddit!"
  string body_markdown = 2;
  // Subreddit ID, eg: "t5_2qjpg"
  string subreddit_id = 3;
  // Author ID, eg: "t2_7gyht"
  string author_id = 4;
  // Is the conversation internal (i.e. mod only)?
  bool is_internal = 5;
  // Type of participant in the conversation, eg: "PARTICIPANT_USER"
  string participant_type = 6;
  // Type of conversation, eg: "SR_USER"
  string conversation_type = 7;
}

message CreateModmailConversationResponse {
  // ID of the created conversation, eg: "qwer42"
  string conversation_id = 1;
}
