syntax = "proto3";

package devvit.plugin.redditapi.widgets;

import "devvit/reddit/common.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.widgets";

message WidgetStyles {
  google.protobuf.StringValue background_color = 1;
  google.protobuf.StringValue header_color = 2;
}

message WidgetImage {
  string url = 1;
  /** required but can be an empty string */
  string link_url = 2;
  int32 height = 3;
  int32 width = 4;
}

message ImageWidget {
  string id = 1;
  string kind = 2;
  repeated WidgetImage data = 3;
  string short_name = 4;
  WidgetStyles styles = 5;
  google.protobuf.StringValue subreddit = 6;
}

message AddImageWidgetRequest {
  string subreddit = 1;
  repeated WidgetImage data = 2;
  string short_name = 3;
  WidgetStyles styles = 4;
}

message UpdateImageWidgetRequest {
  string subreddit = 1;
  string id = 2;
  repeated WidgetImage data = 3;
  string short_name = 4;
  WidgetStyles styles = 5;
}

message CalendarWidgetConfiguration {
  int32 num_events = 1;
  bool show_date = 2;
  bool show_description = 3;
  bool show_location = 4;
  bool show_time = 5;
  bool show_title = 6;
}

message CalendarWidget {
  string id = 1;
  string kind = 2;
  CalendarWidgetConfiguration configuration = 3;
  string google_calendar_id = 4;
  bool requires_sync = 5;
  string short_name = 6;
  WidgetStyles styles = 7;
}

message AddCalendarWidgetRequest {
  string subreddit = 1;
  CalendarWidgetConfiguration configuration = 2;
  string google_calendar_id = 3;
  bool requires_sync = 4;
  string short_name = 5;
  WidgetStyles styles = 6;
}

message UpdateCalendarWidgetRequest {
  string subreddit = 1;
  string id = 2;
  CalendarWidgetConfiguration configuration = 3;
  string google_calendar_id = 4;
  bool requires_sync = 5;
  string short_name = 6;
  WidgetStyles styles = 7;
}

message TextAreaWidget {
  string id = 1;
  string kind = 2;
  string short_name = 3;
  string text = 4;
  WidgetStyles styles = 5;
}

message AddTextAreaWidgetRequest {
  string subreddit = 1;
  string short_name = 2;
  string text = 3;
  WidgetStyles styles = 4;
}

message UpdateTextAreaWidgetRequest {
  string subreddit = 1;
  string id = 2;
  string short_name = 3;
  string text = 4;
  WidgetStyles styles = 5;
}

message WidgetButton {
  message HoverState {
    string kind = 1;
    google.protobuf.StringValue color = 2;
    google.protobuf.StringValue fill_color = 3;
    google.protobuf.StringValue text = 4;
    google.protobuf.StringValue text_color = 5;

    google.protobuf.StringValue image_url = 6;
    google.protobuf.Int32Value height = 7;
    google.protobuf.Int32Value width = 8;
  }

  string kind = 1;
  string text = 2;
  google.protobuf.StringValue url = 3;
  google.protobuf.StringValue image_url = 4;
  google.protobuf.StringValue link_url = 5;
  google.protobuf.StringValue color = 6;
  google.protobuf.StringValue fill_color = 7;
  google.protobuf.StringValue text_color = 8;
  google.protobuf.Int32Value height = 9;
  google.protobuf.Int32Value width = 10;
  HoverState hover_state = 11;
}

message ButtonWidget {
  string id = 1;
  string kind = 2;
  string short_name = 3;
  string description = 4;
  repeated WidgetButton buttons = 5;
  WidgetStyles styles = 6;
}

message AddButtonWidgetRequest {
  string subreddit = 1;
  string short_name = 2;
  string description = 3;
  repeated WidgetButton buttons = 4;
  WidgetStyles styles = 5;
}

message UpdateButtonWidgetRequest {
  string subreddit = 1;
  string id = 2;
  string short_name = 3;
  string description = 4;
  repeated WidgetButton buttons = 5;
  WidgetStyles styles = 6;
}

message CommunityListWidget {
  message CommunityData {
    string community_icon = 1;
    string icon_url = 2;
    bool is_nsfw = 3;
    bool is_subscribed = 4;
    string name = 5;
    string prefixed_name = 6;
    string primary_color = 7;
    int32 subscribers = 8;
    string type = 9;
  }

  string id = 1;
  string kind = 2;
  string short_name = 3;
  repeated CommunityData data = 4;
  WidgetStyles styles = 5;
}

message AddCommunityListWidgetRequest {
  string subreddit = 1;
  string short_name = 2;
  repeated string data = 3;
  WidgetStyles styles = 4;
}

message UpdateCommunityListWidgetRequest {
  string subreddit = 1;
  string id = 2;
  string short_name = 3;
  repeated string data = 4;
  WidgetStyles styles = 5;
}

message UpdateCommunityListWidgetResponse {
  string kind = 1;
  string short_name = 2;
  repeated string data = 3;
  WidgetStyles styles = 4;
}

message PostFlairWidget {
  string id = 1;
  string kind = 2;
  string display = 3;
  repeated string order = 4;
  string short_name = 5;
  WidgetStyles styles = 6;
  google.protobuf.StringValue subreddit = 7;
}

message AddPostFlairWidgetRequest {
  string subreddit = 1;
  string display = 2;
  repeated string order = 3;
  string short_name = 4;
  WidgetStyles styles = 5;
}

message UpdatePostFlairWidgetRequest {
  string subreddit = 1;
  string id = 2;
  string display = 3;
  repeated string order = 4;
  string short_name = 5;
  WidgetStyles styles = 6;
}

message DeleteWidgetRequest {
  string id = 1;
  string subreddit = 2;
}

message GetWidgetsRequest {
  string subreddit = 1;
  google.protobuf.BoolValue progressive_images = 2;
}

message GetWidgetsResponse {
  message WidgetOrdering {
    repeated string order = 1;
  }

  message Layout {
    string id_card_widget = 1;
    WidgetOrdering topbar = 2;
    WidgetOrdering sidebar = 3;
    string moderator_widget = 4;
  }

  message WidgetItem {
    message Data {
      google.protobuf.StringValue url = 1;
      google.protobuf.StringValue link_url = 2;
      google.protobuf.Int32Value height = 3;
      google.protobuf.Int32Value width = 4;
      google.protobuf.StringValue icon_url = 5;
      google.protobuf.StringValue name = 6;
      google.protobuf.StringValue prefixed_name = 7;
      google.protobuf.BoolValue is_subscribed = 8;
      google.protobuf.StringValue type = 9;
      google.protobuf.Int64Value subscribers = 10;
      google.protobuf.StringValue community_icon = 11;
      google.protobuf.BoolValue is_nsfw = 12;
      google.protobuf.StringValue text = 13;
      repeated MenuWidgetItem children = 14;
    }

    message Moderator {
      string name = 1;
      string author_flair_type = 2;
      string author_flair_text_color = 3;
      string author_flair_background_color = 4;
      string author_falir_text = 5;
      repeated devvit.reddit.AuthorFlairRichText author_flair_richtext = 6;
    }

    message PostFlairTemplate {
      string text = 1;
      repeated devvit.reddit.AuthorFlairRichText richtext = 2;
      string background_color = 3;
      string template_id = 4;
      string text_color = 5;
      string type = 6;
    }

    string id = 1;
    string kind = 2;
    WidgetStyles styles = 3;
    string short_name = 4;
    google.protobuf.StringValue description = 5;
    repeated Data data = 6;
    repeated WidgetButton buttons = 7;
    google.protobuf.Int64Value subscribers_count = 8;
    google.protobuf.StringValue currently_viewing_text = 9;
    google.protobuf.Int64Value currently_viewing_count = 10;
    google.protobuf.StringValue subscribers_text = 11;
    google.protobuf.BoolValue show_wiki = 12;
    map<string, PostFlairTemplate> templates = 13;
    google.protobuf.StringValue display = 14;
    repeated string order = 15;
    repeated Moderator mods = 16;
    google.protobuf.Int64Value total_mods = 17;
    google.protobuf.StringValue google_calendar_id = 18;
    google.protobuf.BoolValue requires_sync = 19;
    CalendarWidgetConfiguration configuration = 20;
    google.protobuf.StringValue text = 21;
    google.protobuf.StringValue css = 22;
    google.protobuf.StringValue stylesheet_url = 23;
    google.protobuf.Int64Value height = 24;
    repeated WidgetImage image_data = 25;
  }

  Layout layout = 1;
  map<string, WidgetItem> items = 2;
}

message MenuWidgetItem {
  google.protobuf.StringValue text = 1;
  google.protobuf.StringValue url = 2;
  repeated MenuWidgetItem children = 3;
}

message OrderWidgetsRequest {
  string subreddit = 1;
  repeated string order = 2;
}

message GetWidgetImageUploadLeaseRequest {
  string subreddit = 1;
  string filepath = 2;
  string mimetype = 3;
}

message GetWidgetImageUploadLeaseResponse {
  message S3UploadLease {
    message NameValuePair {
      string name = 1;
      string value = 2;
    }

    string action = 1;
    repeated NameValuePair fields = 2;
  }

  S3UploadLease s3_upload_lease = 1;
  string websocket_url = 2;
}

message CustomWidget {
  string id = 1;
  string kind = 2;
  string short_name = 3;
  string text = 4;
  int32 height = 6;
  string css = 7;
  repeated WidgetImage image_data = 8;
  WidgetStyles styles = 9;
}

message AddCustomWidgetRequest {
  string subreddit = 1;
  string short_name = 2;
  string text = 3;
  int32 height = 4;
  string css = 5;
  repeated WidgetImage image_data = 6;
  WidgetStyles styles = 7;
}

message UpdateCustomWidgetRequest {
  string subreddit = 1;
  string id = 2;
  string short_name = 3;
  string text = 4;
  int32 height = 5;
  string css = 6;
  repeated WidgetImage image_data = 7;
  WidgetStyles styles = 8;
}

// TODO: Menu widgets
