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

syntax = "proto3";

package channelpackage;

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

service ChannelManager {
  // GetStitchedActiveChannelIds (Unary)
  //
  rpc GetStitchedActiveChannelIds(GetStitchedActiveChannelIdsRequest) returns (GetStitchedActiveChannelIdsResponse) {}

  // GetChannelForActiveContent (Unary)
  //
  rpc GetChannelForActiveContent(GetChannelForActiveContentRequest) returns (GetChannelForActiveContentResponse) {}

  // GetTimelinesForActiveContent (Unary)
  //
  rpc GetTimelinesForActiveContent(GetTimelinesForActiveContentRequest) returns (GetTimelinesForActiveContentResponse) {}

  // GetAll (Server Stream)
  //
  rpc GetAll(GetAllRequest) returns (stream Channel) {}

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

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

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

  // GetNonStitchedChannelsWithMultipleScheduledClips (Unary)
  //
  rpc GetNonStitchedChannelsWithMultipleScheduledClips(GetNonStitchedChannelsWithMultipleScheduledClipsParams) returns (GetNonStitchedChannelsWithMultipleScheduledClipsResponse) {}

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

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

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

  // GetChannelById (Unary)
  //
  // Deprecated. Will be removed once client (Stitcher Sequence Lambda) no longer using
  rpc GetChannelById(GetChannelByIdRequest) returns (GetChannelByIdResponse) {}

  // UpdateFields (Unary)
  //
  rpc UpdateFields(UpdateFieldsRequest) returns (UpdateFieldsResponse) {}

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

  rpc BulkDeviceUpdate(BulkDeviceUpdateRequest) returns (BulkDeviceUpdateResponse) {}

  rpc GetChannelQueue(GetChannelQueueRequest) returns (GetChannelQueueResponse) {}
  // GetAllPagedChannelLite (Unary)
  //
  // NOTE: The Lite Version does not support filtering by samsung channel properties
  // Ideally this can be used for the majority of List > Pick List use cases
  rpc GetAllPagedChannelLite(GetAllPagedChannelLiteRequest) returns (GetAllPagedChannelLiteResponse) {}

  rpc GetCFaasIntegratedChannel(GetCFaasIntegratedChannelRequest) returns (GetCFaasIntegratedChannelResponse) {}

  rpc GetOneCFaasIntegratedChannel(GetOneCFaasIntegratedChannelRequest) returns (GetOneCFaasIntegratedChannelResponse) {}

  rpc GetLibrarySumDuration(GetLibrarySumDurationRequest) returns (GetLibrarySumDurationResponse) {}

  rpc GetQueueSumDuration(GetQueueSumDurationRequest) returns (GetQueueSumDurationResponse) {}

  rpc BulkRemoveEpisodesFromQueue(BulkRemoveEpisodesFromQueueRequest) returns (BulkRemoveEpisodesFromQueueResponse) {}

  rpc GetChannelByFilter(GetChannelByFilterRequest) returns (GetChannelByFilterResponse) {}
}

message CreateRequest {
  Channel document = 1;
}

message CreateResponse {
  Channel document = 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;
  bool published = 2;
}

message GetAllPagedChannelLiteRequest {
  // 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 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;
  repeated string projection = 6;
  // 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 = 7;
}

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 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 Channel documents = 1;
  Metadata metadata = 2;
}

message GetAllPagedChannelLiteResponse {
  repeated ChannelLite documents = 1;
  Metadata metadata = 2;
}

message GetAllRequest {
  string region = 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 GetStitchedActiveChannelIdsRequest {
  string active_region = 1;
}

message GetStitchedActiveChannelIdsResponse {
  repeated string ids = 1;
}

message GetChannelForActiveContentRequest {
  string id = 1;
}

message GetChannelForActiveContentResponse {
  string id = 1;
  string name = 2;
  string category = 3;
  string active_region = 4;
  bool is_stitched = 5;
  bool live_broadcast = 6;
}

message GetTimelinesForActiveContentRequest {
  string from = 1;
  string to = 2;
  string channel = 3;
  string sort = 4;
  int32 limit = 5;
  repeated string projection = 6;
}

message GetTimelinesForActiveContentResponse {
  repeated TimelineForActiveContentResponse items = 1;
}

message TimelineForActiveContentResponse {
  string id = 1;
  string start = 2;
  string stop = 3;
  string channel = 4;
}

message GetByIdRequest {
  string id = 1;
  repeated string projection = 2;
}

message GetByIdResponse {
  Channel document = 1;
}

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

message GetByIdsResponse {
  repeated Channel documents = 1;
}

message Distribution {
  repeated string app_names = 1;
  repeated string devices = 2;
}

message Path {
  string path = 1;
}

message MainCategory {
  string id = 1;
  string name = 2;
  int32 order = 3;
  Path svg_image_url = 4;
  Path png_image_url = 5;
  string created_at = 6;
  string updated_at = 7;
  string slug = 8;
  bool pluto_office_only = 9;
  string stacking_order = 10;
  Distribution distribution = 11;
  string active_region = 12;
}

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;
  int32 chat_room_id = 65;
  bool chat_enabled = 66;
  GracenoteIntegration gracenote_integration = 67;
  // mongoose internal revision number; only generated when inserted via mongoose
  int64 v = 68;
  repeated SamsungChannelProperty samsung_channel_properties = 69;
  bool google_dai = 70;
  repeated CustomReferenceValue custom_references = 71;
  Image thumbnail_alt = 72;
  Image featured_image_alt = 73;
  Image logo_alt = 74;
  Image solid_logo_p_n_g_alt = 75;
  Image color_logo_p_n_g_alt = 76;
  Image solid_logo_s_v_g_alt = 77;
  Image color_logo_s_v_g_alt = 78;
  repeated MainCategory main_categories = 79;
  string auto_epg_source = 80;
  CfaasIntegrationResponse cfaas_integration = 81;
  bool logo_overlay_enable = 82;
  bool _is_d_a_s_h_ready_d_r_m = 83 [json_name = "_isDASHReadyDRM"];
  string status = 84;
  repeated string zip_code_distribution = 85;
}

message ChannelLite {
  string id = 1;
  string name = 2;
  string category = 13;
  repeated Category categories = 3;
  string active_region = 4; // not found in inf-lib-schemas
  bool archived = 5;
  bool published = 6;
  int32 number = 7;
}

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

message SamsungChannelProperty {
  string id = 1;
  string channel = 2;
  string service_id = 3;
  bool intiles_enabled = 4;
  string region = 5;
}

message GracenoteIntegration {
  bool enabled = 1;
  string dynamic_clip = 2;
  string series_type = 3;
  string category = 4;
  string sub_category = 5;
  string genre = 6;
  string sub_genre = 7;
}

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 EpisodesQueue {
  string episode = 1;
  int32 order = 2;
}

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

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

message Category {
  string cat_id = 1;
  int32 order = 2;
}

message GetNonStitchedChannelsWithMultipleScheduledClipsParams {}
message GetNonStitchedChannelsWithMultipleScheduledClipsResponse {
  repeated Channel channels = 1;
  message Channel {
    string id = 1;
    string name = 2;
    repeated Clip clips = 3;
    message Clip {
      string id = 1;
      string url = 2;
      repeated Source sources = 3;
      message Source {
        string file = 1;
        string type = 2;
      }
    }
  }
}

// Deprecated. Will be removed once client (Stitcher Sequence Lambda) no longer using
message GetChannelByIdRequest {
  string id = 1;
}

message GetChannelByIdResponse {
  Channel channel = 1;
}

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

message UpdateFieldsResponse {
  Channel document = 1;
}

message BulkDeviceUpdateRequest {
  repeated string devices = 1;
  repeated string include_group = 2;
  repeated string exclude_group = 3;
  repeated string remove_group = 4;
}

message BulkDeviceUpdateResponse {}

message GetChannelQueueRequest {
  string channel_id = 1;
  // filter episodes by partial name match
  string name = 2;
  // optional - unix timestamp ms
  int64 start = 3;
  // optional - unix timestamp ms
  int64 end = 4;
  // optional - Accepted values are'completed' or 'on air'
  repeated string status = 5;
  string rating = 6;
  string genre = 7;
  int32 season = 8;
  int32 number = 9;
  string age_range = 10;
  string tmsid = 11;
  // how many results to return
  int32 limit = 12;
  // where to begin, default 0
  int32 offset = 13;
  repeated GetAllPagedSort sort = 14;
  string updated_at = 15;
  repeated string tags = 16;
}

message GetChannelQueueResponse {
  repeated Episode documents = 1;
  Metadata metadata = 2;
}

message Episode {
  string id = 1;
  string name = 2;
  string rating = 3;
  int32 season = 4;
  int32 number = 5;
  repeated AgeRange age_range = 6;
  string tmsid = 7;
  int32 duration = 8;
  string last_aired = 9;
  string first_aired = 10;
  NextTimelineDetails next_timeline = 11;
  Series series = 12;
  int32 allotment = 13;
  bool featured = 14;
  bool flagged = 15;
  AvailabilityWindows availability_windows = 16;
  repeated Source sources = 17;
  string updated_at = 18;
  bool all_clips_ready = 19;
  bool is_available_now = 20;
  bool has_unique_provider = 21;
  bool has_mixed_provider_with = 22;
  bool has_clip_with_empty_sources = 23;
  bool has_linear_availability_windows = 24;
  string author = 25;
  string status = 26;
  string genre = 27;
  bool has_ad_pods = 28;
  bool published = 29;
  int32 order = 30;
  repeated string tags = 31;
  bool has_live_broadcast = 32;
}

message NextTimelineDetails {
  string id = 1;
  string channel = 2;
  string start = 3;
}

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

message Source {
  string id = 1;
  ClipDetails clip = 2;
}

message ClipDetails {
  string content_status = 1;
  Author author = 2;
}

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 LinearWindow {
  string start_date = 1;
  string end_date = 2;
  int32 screenings = 3;
}

message AVODWindow {
  string start_date = 1;
  string end_date = 2;
  bool ad_free = 3;
  int32 screenings = 4;
}

message AgeRange {
  string id = 1;
  int32 min = 2;
  int32 max = 3;
  string display_name = 4;
}

message Author {
  string name = 1;
}

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

message SourceIdProjection {
  bool key = 1;
  bool value = 2;
}

message CfaasIntegrationParams {
  bool enabled = 1;
  string clip_id = 2;
  SourceId source_id = 3;
}

message CfaasIntegrationResponse {
  bool enabled = 1;
  string clip_id = 2;
  SourceId source_id = 3;
  string category = 4;
  string sub_category = 5;
  string genre = 6;
  string sub_genre = 7;
}

message cfaasIntegrationProjection {
  bool enabled = 1;
  bool clip_id = 2;
  SourceIdProjection source_id = 3;
  bool category = 4;
  bool sub_category = 5;
  bool genre = 6;
  bool sub_genre = 7;
}

message GetCFaasIntegratedChannelProjection {
  bool id = 1;
  bool name = 2;
  bool summary = 3;
  bool description = 4;
  bool metadata_language = 5;
  bool active_region = 6;
  bool published = 7;
  bool tags = 8;
  bool auto_epg_source = 9;
  cfaasIntegrationProjection cfaas_integration = 10;
}

message GetCFaasIntegratedChannel {
  string id = 1;
  string name = 2;
  string summary = 3;
  string description = 4;
  string metadata_language = 5; // not in schema
  string active_region = 6;
  bool published = 7;
  repeated string tags = 8;
  string auto_epg_source = 9;
  CfaasIntegrationResponse cfaas_integration = 10;
}

message GetCFaasIntegratedChannelRequest {
  string auto_epg_source = 1;
  CfaasIntegrationParams cfaas_integration = 2;
  GetCFaasIntegratedChannelProjection projection = 3;
}

message GetCFaasIntegratedChannelResponse {
  repeated GetCFaasIntegratedChannel documents = 1;
}

message GetOneCFaasIntegratedChannelRequest {
  string auto_epg_source = 1;
  CfaasIntegrationParams cfaas_integration = 2;
}

message GetOneCFaasIntegratedChannelResponse {
  GetCFaasIntegratedChannel document = 1;
}

message GetLibrarySumDurationRequest {
  string channel_id = 1;
  string name = 2;
  // optional - unix timestamp ms
  int64 start = 3;
  // optional - unix timestamp ms
  int64 end = 4;
  // optional - Accepted values are'completed' or 'on air'
  repeated string status = 5;
  string rating = 6;
  string genre = 7;
  int32 season = 8;
  int32 number = 9;
  string age_range = 10;
  string tmsid = 11;
  string updated_at = 14;
}

message GetLibrarySumDurationResponse {
  int32 sum_duration = 1;
}

message GetQueueSumDurationRequest {
  string channel_id = 1;
  // filter episodes by partial name match
  string name = 2;
  // optional - unix timestamp ms
  int64 start = 3;
  // optional - unix timestamp ms
  int64 end = 4;
  // optional - Accepted values are'completed' or 'on air'
  repeated string status = 5;
  string rating = 6;
  string genre = 7;
  int32 season = 8;
  int32 number = 9;
  string age_range = 10;
  string tmsid = 11;
  string updated_at = 14;
  repeated string tags = 15;
}

message GetQueueSumDurationResponse {
  int32 sum_duration = 1;
}

message BulkRemoveEpisodesFromQueueRequest {
  repeated string ids = 1;
}

message BulkRemoveEpisodesFromQueueResponse {
  string response = 1;
}

message GetChannelByFilterRequest {
  string slug = 1;
  bool published = 2;
}

message GetChannelByFilterResponse {
  Channel document = 1;
}
