/*
 * Created by jonathan.jesperson@pluto.tv on 10/21/2020.
 * Copyright (c) PlutoTV Inc 2020.
 */

syntax = "proto3";

package seriespackage;

option go_package = "github.com/Pluto-tv/service-dal/golang_client";
option java_package = "tv.pluto.ip.dal.series";

service SeriesManager {
  // GetById (Unary)
  //
  rpc GetById(GetByIdRequest) returns (GetByIdResponse) {}

  // GetPopulatedSeriesById (Unary)
  // The default populated episode when no `populate` is provided is the entire populated object. For performance
  // reason it may be desirable to request less / only needed values
  rpc GetPopulatedSeriesById(GetPopulatedSeriesByIdRequest) returns (GetPopulatedSeriesByIdResponse) {}

  // GetByIds (Unary)
  //
  rpc GetByIds(GetByIdsRequest) returns (GetByIdsResponse) {}

  // GetDocumentsUpdatedBetweenDates (Server Stream)
  //
  rpc GetDocumentsUpdatedBetweenDates(GetDocumentsUpdatedBetweenDatesRequest) returns (stream Series) {}

  // UpdateContentMamUniqueIdsByIds (Unary)
  //
  rpc UpdateContentMamUniqueIdsByIds(UpdateContentMamUniqueIdsByIdsRequest) returns (UpdateContentMamUniqueIdsByIdsResponse) {}

  // CFeedsSyncDocuments (Server Stream)
  //
  rpc CFeedsSyncDocuments(CFeedsSyncDocumentsRequest) returns (stream Series) {}

  // CFeedsSyncAllIds (Server Stream)
  //
  rpc CFeedsSyncAllIds(CFeedsSyncAllIdsRequest) returns (stream Id) {}

  // GetSeriesById (Unary)
  //
  // Deprecated. Will be removed once client (FW IVI) no longer using
  rpc GetSeriesById(GetSeriesByIdRequest) returns (GetSeriesByIdResponse) {}

  rpc UpdateFields(UpdateFieldsRequest) returns (UpdateFieldsResponse) {}

  // DeleteById (Unary)
  //
  rpc DeleteById(DeleteByIdRequest) returns (DeleteByIdResponse) {}

  // Create (Unary)
  //
  rpc Create(CreateRequest) returns (CreateResponse) {}

  // GetSeriesUsingExternalId (Unary)
  // Retrieves series data based on an external identifier and additional query parameters.
  rpc GetSeriesUsingExternalId(GetSeriesUsingExternalIdRequest) returns (GetSeriesUsingExternalIdResponse) {}

  // GetSeriesPartnerByIds (Unary)
  //
  rpc GetSeriesPartnerByIds(GetSeriesPartnerByIdsRequest) returns (GetSeriesPartnerByIdsResponse) {}

  // GetAllPaged (Unary)
  //
  rpc GetAllPaged(GetAllPagedRequest) returns (GetAllPagedResponse) {}

  // GetSeriesByChannelId (Unary)
  //
  rpc GetSeriesByChannelId(GetSeriesByChannelIdRequest) returns (GetSeriesByChannelIdResponse) {}
  //GetSeriesByNameAndActiveRegionAndCustomReferences (Unary)
  //
  rpc GetSeriesByNameAndActiveRegionAndCustomReferences(GetSeriesByNameAndActiveRegionAndCustomReferencesRequest) returns (GetSeriesByNameAndActiveRegionAndCustomReferenceResponse) {}

  //GetSeriesFutureTimeline
  //
  rpc GetSeriesFutureTimeline(GetSeriesFutureTimelineRequest) returns (GetSeriesFutureTimelineResponse) {}

  // UpdateRatings (Unary)
  //
  rpc UpdateRatings(UpdateRatingsRequest) returns (UpdateRatingsResponse) {}
}

message GetSeriesPartnerByIdsRequest {
  repeated string ids = 1;
}

message GetSeriesPartnerByIdsResponse {
  repeated SeriesPartner documents = 1;
}
message SeriesPartner {
  string id = 1;
  string author = 2;
}

message CreateRequest {
  Series document = 1;
}

message CreateResponse {
  Series document = 1;
}

message GetPopulatedSeriesByIdRequest {
  string id = 1;
  // optional path population mapped to query
  // allowed values:
  //    channels
  //    { path: 'vodCategoryEntries', populate: { path: 'vodCategory' } }
  //   { path: 'customReferences', populate: { path: 'value' } }
  repeated PopulatePath populate = 2;
}
message PopulatePath {
  string path = 1;
  PopulatePath populate = 2;
}
message GetPopulatedSeriesByIdResponse {
  SeriesPopulated series = 1;
}

message SeriesPopulated {
  string id = 1;
  string updated_at = 2;
  string created_at = 3;
  string name = 4;
  bool published = 5;
  string display_name = 6;
  string slug = 7;
  repeated Season seasons = 8;
  repeated Channel channels = 9;
  string type = 10;
  string category = 11;
  string sub_category = 12;
  string genre = 13;
  string sub_genre = 14;
  repeated string tags = 15;
  string summary = 16;
  string description = 17;
  string notes = 18;
  Image thumbnail = 19;
  Image featured_image = 20;
  Image partner_logo = 21;
  Image poster = 22;
  Image tile = 23;
  int32 episode_count = 24;
  int32 season_count = 25;
  bool user_generated = 26;
  DistributeAs distribute_as = 27;
  repeated VodCategoryEntry vod_category_entries = 28;
  bool pluto_tv_o_o = 29;
  string tmsid = 30;
  string active_region = 31; // not in schema
  string metadata_language = 32; // not in schema
  repeated string region_filter = 33; // not in schema
  string rating = 34; // not in schema
  AvailabilityWindows availability_windows = 35; // not in schema
  string available_date = 36; // not in schema
  string expiration_date = 37; // not in schema
  bool expiration_set_manually = 38; // not in schema
  string content_u_u_i_d = 39;
  repeated string seo_aliases = 40;
  Image poster16_9 = 41 [json_name = "poster16_9"];
  repeated CustomReferencePopulated custom_references = 42;
  repeated string rating_descriptors = 43;
  string content_timestamp = 44;
  repeated ExternalId external_ids = 45;
}

message Channel {
  string id = 1;
  string created_at = 2;
  string updated_at = 3;
  string name = 4;
  string author = 5;
  string parent = 6;
  string hash = 7;
  int32 number = 8;
  int32 cohort_mask = 9;
  int32 access_code = 10;
  bool published = 11;
  string description = 12;
  string category = 13;
  repeated Category categories = 14;
  bool auto_schedule = 15;
  int32 auto_schedule_days = 16;
  string summary = 17;
  repeated string tags = 18;
  repeated string geo_targets = 19;
  bool kids_mode = 20;
  int32 featured = 21;
  string created = 22;
  string updated = 23;
  string visibility = 24;
  Image thumbnail = 25;
  Image featured_image = 26;
  Image partner_logo = 27;
  Image logo = 28;
  Image tile = 29;
  Image tile_grayscale = 30;
  Image browse = 31;
  Image background = 32;
  string notes = 33;
  string type = 34;
  string start = 35;
  string stop = 36;
  int32 redirect = 37;
  bool on_demand = 38;
  string on_demand_description = 39;
  bool archived = 40;
  string slug = 41;
  RegionFilter region_filter = 42;
  repeated int32 dma_distribution = 43;
  RegionFilter distribution = 44;
  repeated EpisodesQueue episodes_queue = 45;
  repeated string overlays = 46;
  bool direct_only = 47;
  bool live_broadcast = 48;
  bool has_sub_clips = 49;
  bool is_stitched = 50;
  bool render_interstitials = 51;
  bool pluto_office_only = 52;
  PrivateChannel private_channel = 53;
  ScheduledPublishing scheduled_publishing = 54;
  Image solid_logo_p_n_g = 55;
  Image color_logo_p_n_g = 56;
  Image solid_logo_s_v_g = 57;
  Image color_logo_s_v_g = 58;
  repeated string supported_channel_caption_languages = 59;
  string tmsid = 60;
  string active_region = 61; // not found in inf-lib-schemas
  int32 category_mask = 62; // not found in inf-lib-schemas
  string metadata_language = 63; // not found in inf-lib-schemas
  repeated string seo_aliases = 64;
  Image thumbnail_alt = 65;
  Image featured_image_alt = 66;
  Image logo_alt = 67;
  Image solid_logo_p_n_g_alt = 68;
  Image color_logo_p_n_g_alt = 69;
  Image solid_logo_s_v_g_alt = 70;
  Image color_logo_s_v_g_alt = 71;
}

message EpisodesQueue {
  string episode = 1;
  int32 order = 2;
}

message RegionFilter {
  repeated string include = 1;
  repeated string exclude = 2;
}
message ScheduledPublishing {
  string start = 1;
  string end = 2;
  bool active = 3;
}

message PrivateChannel {
  string created_by = 1;
  string subscriber_code = 2;
  string publisher_code = 3;
  string endpoint = 4;
  string stream_name = 5;
  string episode = 6;
  string series = 7;
  string clip = 8;
  string episode_name = 9;
  string subscriber_count = 10;
}
message Category {
  string cat_id = 1;
  int32 order = 2;
}
message VodCategory {
  string id = 1;
  string name = 2;
  string display_name = 3;
  int32 order = 4;
  bool enabled = 5;
  bool pluto_office_only = 6;
  string enabled_at = 7;
  string description = 8;
  RegionFilter region_filter = 9;
  RegionFilter distribution = 10;
  string intile_channel = 11;
  int32 intile_order = 12;
  Path icon_svg = 13;
  Path icon_png = 14;
  Path image_featured = 15;
  string created_at = 16;
  string updated_at = 17;
  string disabled_at = 18;
  string active_region = 19;
  bool kids_mode = 20;
  repeated Category categories = 21;
  repeated CustomReference custom_references = 22;
  bool archived = 23;
  bool hero_carousel = 24;

  message Path {
    string path = 1;
  }

  message RegionFilter {
    repeated string include = 1;
    repeated string exclude = 2;
  }
}

message CustomReference {
  string id = 1;
  string type = 2;
  string value = 3;
}

message VodCategoryEntry {
  string id = 1;
  VodCategory vod_category = 2;
  string episode = 3;
  string series = 4;
  int32 order = 5;
  string created_at = 6;
  string updated_at = 7;
}
message CustomReferencePopulated {
  string id = 1;
  string type = 2;
  Partner value = 3;
}

message Partner {
  string id = 1;
  string name = 2;
}

message CFeedsSyncAllIdsRequest {}

message Id {
  string id = 1;
}

message CFeedsSyncDocumentsRequest {
  // Expressed as a valid javascript Date, https://en.wikipedia.org/wiki/ISO_8601
  string last_run_at = 1;
}

message GetDocumentsUpdatedBetweenDatesRequest {
  // Expressed as a valid javascript Date, https://en.wikipedia.org/wiki/ISO_8601
  string updated_at_min = 1;
  // Expressed as a valid javascript Date, https://en.wikipedia.org/wiki/ISO_8601
  string updated_at_max = 2;
}

message GetByIdRequest {
  string id = 1;
}

message GetByIdResponse {
  Series document = 1;
}

message GetByIdsRequest {
  repeated string ids = 1;
  repeated GetAllPagedSort sort = 2;
  repeated string projection = 3;
}

message GetAllPagedSort {
  // field to sort on
  string field = 1;
  // sort direction 1 | -1
  int32 value = 2;
}

message GetByIdsResponse {
  repeated Series documents = 1;
}

message Series {
  string id = 1;
  string updated_at = 2;
  string created_at = 3;
  string name = 4;
  bool published = 5;
  string display_name = 6;
  string slug = 7;
  repeated Season seasons = 8;
  repeated string channels = 9;
  string type = 10;
  string category = 11;
  string sub_category = 12;
  string genre = 13;
  string sub_genre = 14;
  repeated string tags = 15;
  string summary = 16;
  string description = 17;
  string notes = 18;
  Image thumbnail = 19;
  Image featured_image = 20;
  Image partner_logo = 21;
  Image poster = 22;
  Image tile = 23;
  int32 episode_count = 24;
  int32 season_count = 25;
  bool user_generated = 26;
  DistributeAs distribute_as = 27;
  repeated string vod_category_entries = 28;
  bool pluto_tv_o_o = 29;
  string tmsid = 30;
  string active_region = 31; // not in schema
  string metadata_language = 32; // not in schema
  repeated string region_filter = 33; // not in schema
  string rating = 34; // not in schema
  AvailabilityWindows availability_windows = 35; // not in schema
  string available_date = 36; // not in schema
  string expiration_date = 37; // not in schema
  bool expiration_set_manually = 38; // not in schema
  string content_u_u_i_d = 39;
  repeated string seo_aliases = 40;
  Image poster16_9 = 41 [json_name = "poster16_9"];
  repeated CustomReference custom_references = 42;
  repeated string rating_descriptors = 43;
  string content_timestamp = 44;
  repeated ExternalId external_ids = 45;
}

message SeriesDetails {
  string id = 1;
  string name = 2;
  string updated_at = 3;
}

message AvailabilityWindows {
  repeated Window _a_v_o_d = 1 [json_name = "AVOD"];
  repeated Window linear = 2;
}

message Window {
  string start_date = 1;
  string end_date = 2;
  string id = 3;
  int32 current_screenings = 4;
  int32 screenings = 5;
}

message Season {
  int32 number = 1;
  string synopsis = 2;
}

message Image {
  string path = 1;
  string title = 2;
}

message DistributeAs {
  bool _t_v_o_d = 1 [json_name = "TVOD"];
  bool _a_v_o_d = 2 [json_name = "AVOD"];
  bool _s_v_o_d = 3 [json_name = "SVOD"];
  bool linear = 4;
}

message UpdateContentMamUniqueIdsByIdsRequest {
  repeated ObjectIdContentIdSet object_id_content_id_sets = 1;
}

message ObjectIdContentIdSet {
  string id = 1;
  string content_u_u_i_d = 2;
}

message UpdateContentMamUniqueIdsByIdsResponse {}

// Deprecated. Will be removed once client (FW IVI) no longer using
message GetSeriesByIdRequest {
  string id = 1;
}

message GetSeriesByIdResponse {
  Series series = 1;
}

message UpdateFieldsRequest {
  string id = 1;
  Series document = 2;
  repeated string update_fields = 3;
}

message UpdateFieldsResponse {
  Series document = 1;
}

message DeleteByIdRequest {
  string id = 1;
}

message DeleteByIdResponse {
  int64 deleted_count = 1;
}

message ExternalId {
  string key = 1;
  string value = 2;
}

message GetSeriesUsingExternalIdRequest {
  string key = 1;
  string value = 2;
  bool published = 3;
  string type = 4;
  repeated string channels = 5;
  string active_region = 6;
  repeated string tags = 7;
  string genre = 8;
  string sub_genre = 9;
  string category = 10;
  string sub_category = 11;
}

message GetSeriesUsingExternalIdResponse {
  repeated Series documents = 1;
}

message Metadata {
  int32 current_offset = 1;
  int32 total_items = 2;
}

message GetAllPagedRequest {
  // how many results to return default 1000
  int32 limit = 1;
  // where to begin page default 0
  int32 offset = 2;
  // how to sort results
  repeated GetAllPagedSort sort = 3;
  // when set to true the `total count` metadata will not be calculated
  // this can save some performance as count is additional query
  bool disable_total_count = 4;
  repeated Filter filters = 5;
  // when set to true the `name` value will be sent to MongoDB as regex expression
  // when set to false the `name` value will be sent to MongoDB as a literal string
  bool enable_regex = 6;
}

message GetAllPagedResponse {
  repeated Series documents = 1;
  Metadata metadata = 2;
}

message Filter {
  // field to filter on
  string field = 1;
  // value for the filter
  string value = 2;
  // type of the filter string (default), number, bool
  string type = 3;
  // operator to filter by (values must be AND or OR)
  string operator = 4;
}

message GetSeriesByChannelIdRequest {
  string id = 1;
}

message GetSeriesByChannelIdResponse {
  repeated SeriesDetails documents = 1;
}

message GetSeriesByNameAndActiveRegionAndCustomReferencesRequest {
  string name = 1;
  string active_region = 2;
  repeated CustomReference custom_references = 3;
}

message GetSeriesByNameAndActiveRegionAndCustomReferenceResponse {
  Series document = 1;
}

message SeriesFutureTimeline {
  string timeline_id = 1;
  string timeline_start = 2;
  string timeline_stop = 3;
  string episode_id = 4;
  string episode_name = 5;
}

message GetSeriesFutureTimelineRequest {
  string series_id = 1;
  string channel_id = 2;
}

message GetSeriesFutureTimelineResponse {
  repeated SeriesFutureTimeline documents = 1;
}

message UpdateRatingsRequest {
  string series_id = 1;
  string rating = 2;
  bool replace = 3;
}

message UpdateRatingsResponse {
  Series document = 1;
  repeated ClipWithRating clips_with_more_restrictive_ratings = 2;
}

message ClipWithRating {
  string id = 1;
  string name = 2;
  string rating = 3;
}
