/*
 * Created by jonathan.jesperson@pluto.tv on 01/26/2021.
 * Copyright (c) PlutoTV Inc 2021.
 */

syntax = "proto3";

package vodcategoryentrypackage;

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

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

  // GetVodCategoryEntriesByVodCategoryId (Unary)
  //
  rpc GetVodCategoryEntriesByVodCategoryId(GetVodCategoryEntriesByVodCategoryIdRequest) returns (GetVodCategoryEntriesByVodCategoryIdResponse) {}

  // GetVodCategoryEntriesBySeriesOrEpisodeIds (Unary)
  //
  rpc GetVodCategoryEntriesBySeriesOrEpisodeIds(GetVodCategoryEntriesBySeriesOrEpisodeIdsRequest) returns (GetVodCategoryEntriesBySeriesOrEpisodeIdsResponse) {}

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

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

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

  rpc UpdateFields(UpdateFieldsRequest) returns (UpdateFieldsResponse) {}

  rpc Create(CreateRequest) returns (CreateResponse) {}

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

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

  // BulkAddVodCategoryEntries (Unary)
  //
  rpc BulkAddVodCategoryEntries(BulkAddVodCategoryEntriesRequest) returns (BulkAddVodCategoryEntriesResponse) {}

  // BulkDeleteVodCategoryEntries (Unary)
  //
  rpc BulkDeleteVodCategoryEntries(BulkDeleteVodCategoryEntriesRequest) returns (BulkDeleteVodCategoryEntriesResponse) {}

  // UpdateOrder (Unary)
  //
  rpc UpdateOrder(UpdateOrderRequest) returns (UpdateOrderResponse) {}

  // GetPopulatedEntriesByVodCategoryId (Unary)
  //
  rpc GetPopulatedEntriesByVodCategoryId(GetPopulatedEntriesByVodCategoryIdRequest) returns (GetPopulatedEntriesByVodCategoryIdResponse) {}

  // GetEntriesDurationsSumByVodCategoryId (Unary)
  //
  rpc GetEntriesDurationsSumByVodCategoryId(GetEntriesDurationsSumByVodCategoryIdRequest) returns (GetEntriesDurationsSumByVodCategoryIdResponse) {}
  // GetVodCategoryEntriesByVodCategoryIds (Unary)
  //
  rpc GetVodCategoryEntriesByVodCategoryIds(GetVodCategoryEntriesByVodCategoryIdsRequest) returns (GetVodCategoryEntriesByVodCategoryIdsResponse) {}

  // GetFilteredVodCategoryEntries (Unary)
  //
  rpc GetFilteredVodCategoryEntries(GetFilteredVodCategoryEntriesRequest) returns (GetFilteredVodCategoryEntriesResponse) {}
}

message GetByIdRequest {
  string id = 1;
}

message GetByIdResponse {
  VodCategoryEntry document = 1;
}

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;
  repeated Filter filters = 4;
  // 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 = 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 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;
}
message GetAllPagedSort {
  // field to sort on
  string field = 1;
  // sort direction 1 | -1
  int32 value = 2;
}

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

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

message DeleteByIdRequest {
  string id = 1;
}

message DeleteByIdResponse {
  int64 deleted_count = 1;
}

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 GetVodCategoryEntriesByVodCategoryIdResponse {
  repeated VodCategoryEntry documents = 1;
}

message GetVodCategoryEntriesByVodCategoryIdRequest {
  string id = 1;
}

message GetVodCategoryEntriesBySeriesOrEpisodeIdsRequest {
  repeated string episode_ids = 1;
  repeated string series_ids = 2;
  repeated string projection = 3;
}

message GetVodCategoryEntriesBySeriesOrEpisodeIdsResponse {
  repeated VodCategoryEntry documents = 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 VodCategoryEntry {
  string id = 1;
  string vod_category = 2;
  string episode = 3;
  string series = 4;
  int32 order = 5;
  string created_at = 6;
  string updated_at = 7;
}

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

message UpdateFieldsResponse {
  VodCategoryEntry document = 1;
}

message CreateRequest {
  VodCategoryEntry document = 1;
}

message CreateResponse {
  VodCategoryEntry document = 1;
}

message BulkAddVodCategoryEntriesRequest {
  string vod_category_id = 1;
  repeated string episode_ids = 2;
  repeated string series_ids = 3;
}

message BulkAddVodCategoryEntriesResponse {
  repeated VodCategoryEntry documents = 1;
}

message BulkDeleteVodCategoryEntriesRequest {
  string vod_category_id = 1;
  repeated string episode_ids = 2;
  repeated string series_ids = 3;
}

message BulkDeleteVodCategoryEntriesResponse {
  repeated VodCategoryEntry documents = 1;
}

message UpdateOrderElement {
  string id = 1;
  int32 order = 2;
}

message UpdateOrderRequest {
  string vod_category_id = 1;
  repeated UpdateOrderElement documents = 2;
}

message UpdateOrderResponse {
  repeated UpdateOrderElement documents = 1;
}

message GetPopulatedEntriesByVodCategoryIdRequest {
  string id = 1;
  repeated SortOptions sort_options = 2;
  int32 offset = 3;
  int32 limit = 4;
}

message SortOptions {
  string field = 1;
  int32 value = 2;
}

message GetPopulatedEntriesByVodCategoryIdResponse {
  repeated PopulatedVodCategoryEntry documents = 1;
  int32 current_offset = 3;
  int32 total_items = 4;
}

message PopulatedVodCategoryEntry {
  string id = 1;
  string vod_category = 2;
  Episode episode = 3;
  Series series = 4;
  int32 order = 5;
  string created_at = 6;
  string updated_at = 7;
}

message Series {
  string id = 1;
  string updated_at = 2;
  string created_at = 3;
  string name = 4;
  bool published = 5;
  string type = 10;
  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;
  string active_region = 26; // not in schema
  string metadata_language = 27; // not in schema
  repeated string region_filter = 28;
  AvailabilityWindows availability_windows = 29;
  string available_date = 30; // not in schema
  int32 vod_category_entries_count = 31;
  int32 duration = 32;
  string genre = 33;
  string sub_genre = 34;
  string category = 35;
  string sub_category = 36;
}

message Episode {
  string id = 1;
  string name = 2;
  int32 season = 3;
  int32 number = 4;
  int32 duration = 5;
  SeriesSummary series = 6;
  AvailabilityWindows availability_windows = 7;
  string updated_at = 8;
  bool all_clips_ready = 9;
  bool has_unique_provider = 10;
  string genre = 11;
  bool published = 12;
  string created_at = 13;
  string display_name = 14;
  string display_on_guide = 15;
  bool ad_pods_verified = 16;
  int32 ad_pods_duration = 17;
  string category = 18;
  string sub_category = 19;
  Image thumbnail = 20;
  Image featured_image = 21;
  Image partner_logo = 22;
  Image poster = 23;
  Image screenshot16_9 = 24 [json_name = "screenshot16_9"];
  Image screenshot4_3 = 25 [json_name = "screenshot4_3"];
  string active_region = 26; // not in schema
  string metadata_language = 27; // not in schema
  repeated string region_filter = 28;
  int32 vod_category_entries_count = 29;
  int32 ad_pods = 30;
  bool promotional_adpods = 31;
  bool is_available_now = 32;
  bool has_mixed_provider_with = 33;
  bool has_clip_with_empty_sources = 34;
  bool has_linear_availability_windows = 35;
  string sub_genre = 36;
}

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 screenings = 5;
}

message SeriesSummary {
  string id = 1;
  string name = 2;
  string type = 3;
}

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

message GetVodCategoryEntriesByVodCategoryIdsResponse {
  repeated VodCategoryEntry documents = 1;
}

message GetVodCategoryEntriesByVodCategoryIdsRequest {
  repeated string ids = 1;
}

message GetEntriesDurationsSumByVodCategoryIdRequest {
  string id = 1;
}

message GetEntriesDurationsSumByVodCategoryIdResponse {
  int32 duration = 1;
}

message CustomFilter {
  repeated string tags = 1;
  string genre = 2;
  string category = 3;
  string sub_category = 4;
  string sub_genre = 5;
  string rating = 6;
  string metadata_language = 7;
  string created_at = 8;
  string series_name = 9;
  string series_type = 10;
  AvailabilityWindowsFilter availability_windows = 11;
}

message AvailabilityWindowsFilter {
  string type = 1;
  string start_date = 2;
  string end_date = 3;
}

message Projection {
  repeated string episode = 1;
  repeated string series = 2;
}

message GetFilteredVodCategoryEntriesRequest {
  int32 limit = 1;
  int32 offset = 2;
  CustomFilter filters = 3;
  Projection projection = 4;
}

message GetFilteredVodCategoryEntriesResponse {
  repeated FilteredVodCategoryEntry documents = 1;
  Metadata metadata = 2;
}

message FilteredVodCategoryEntry {
  string id = 1;
  string vod_category = 2;
  FilteredEpisode episode = 3;
  FilteredSeries series = 4;
  int32 order = 5;
  string created_at = 6;
  string updated_at = 7;
}

message FilteredSeries {
  string id = 1;
  string name = 2;
  string type = 3;
  string metadata_language = 4;
  string category = 5;
  string sub_category = 6;
  string genre = 7;
  string sub_genre = 8;
  string rating = 9;
  AvailabilityWindows availability_windows = 10;
  repeated string tags = 11;
}

message FilteredEpisode {
  repeated string tags = 1;
  string id = 2;
  string name = 3;
  string rating = 4;
  string metadata_language = 5;
  AvailabilityWindows availability_windows = 6;
  string genre = 7;
  string category = 8;
  string sub_category = 9;
  string sub_genre = 10;
}
