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

syntax = "proto3";

package partnerpackage;

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

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

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

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

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

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

  // GetPartnersByIds (Unary)
  //
  // Deprecated. Will be removed once client (FW IVI) no longer using
  rpc GetPartnersByIds(GetPartnersByIdsRequest) returns (GetPartnersByIdsResponse) {}

  rpc GetItemsAll(GetItemsAllRequest) returns (GetItemsAllResponse) {}

  rpc GetItemsByIds(GetItemsByIdsRequest) returns (GetItemsByIdsResponse) {}

  rpc GetAllPaged(GetAllPagedRequest) returns (GetAllPagedResponse) {}

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

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

  // GetByApiAuthorName (Unary)
  //
  rpc GetByApiAuthorName(GetByApiAuthorNameRequest) returns (GetByApiAuthorNameResponse) {}

  // GetByFilter (Unary)
  //
  rpc GetByFilter(GetByFilterRequest) returns (GetByFilterResponse) {}
}

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 {
  Partner 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 Partner documents = 1;
}

message LogoOverlay {
  string path = 1;
}

message Partner {
  string id = 1;
  string updated_at = 2;
  string created_at = 3;
  string name = 4;
  Api api = 5;
  bool is_blu_evo = 6;
  string ingestor = 7;
  bool use_lambda = 8;
  string bluevo_api_version = 9;
  string api_author_name = 10;
  bool auto_ingestion = 11;
  string ingestion_interval = 12;
  repeated string feeds = 13;
  bool captions_required = 14;
  Advertising advertising = 15;
  string code = 16;
  AdvertisingId advertising_id = 17;
  ComScore com_score = 18;
  string parent = 19;
  DistributeAs distribute_as = 20;
  string encoding_profile = 21;
  repeated string region_clone = 22;
  repeated string partner_type = 23;
  LogoOverlay logo_overlay = 24;
}

message Api {
  string key = 1;
  string secret = 2;
  string endpoint = 3;
}

message Advertising {
  string tag = 1;
}

message AdvertisingId {
  string android = 1;
  string android_mobile = 2 [json_name = "android-mobile"];
  string chromecast = 3;
  string ctv = 4;
  string desktop = 5;
  string gom = 6;
  string hisense = 7;
  string ios = 8;
  string km = 9;
  string metrological = 10;
  string mobile = 11;
  string msn = 12;
  string lg_webos = 13 [json_name = "lg-webos"];
  string now_tv = 14 [json_name = "now-tv"];
  string opera_other = 15 [json_name = "opera-other"];
  string ps3 = 16;
  string ps4 = 17;
  string ps5 = 18;
  string roku = 19;
  string samsung_orsay = 20 [json_name = "samsung-orsay"];
  string samsung_tizen = 21 [json_name = "samsung-tizen"];
  string samsung_tvplus = 22 [json_name = "samsung-tvplus"];
  string sky_q = 23 [json_name = "sky-q"];
  string tivo = 24;
  string tvos = 25;
  string vizio = 26;
  string viziovia = 27;
  string web = 28;
  string xbox360 = 29;
  string xboxone = 30;
}

message ComScore {
  string c1 = 1;
  string c2 = 2;
  string c3 = 3;
  string c4 = 4;
  string c6 = 5;
}

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;
}

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

message GetPartnersByIdsResponse {
  repeated Partner partners = 1;
}

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

message GetItemsAllRequest {
  string id = 1;
}

message PartnerContentItem {
  string id = 1;
  string slug = 2;
  string content_type = 3;
  string series_id = 4;
  string series_slug = 5;
  repeated ExternalId external_ids = 6;
}

message GetItemsAllResponse {
  repeated PartnerContentItem items = 1;
}

message GetItemsByIdsRequest {
  repeated string external_ids = 1;
  string id = 2;
}

message GetItemsByIdsResponse {
  repeated PartnerContentItem items = 1;
}

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 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 Metadata {
  int32 current_offset = 1;
  int32 total_items = 2;
}

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

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

message UpdateFieldsResponse {
  Partner document = 1;
}

message CreateRequest {
  Partner document = 1;
}

message CreateResponse {
  Partner document = 1;
}

message GetByApiAuthorNameRequest {
  string api_author_name = 1;
}

message GetByApiAuthorNameResponse {
  Partner document = 1;
}

message GetByFilterRequest {
  bool is_id = 1;
  string partner_id = 2;
  string api_author_name = 3;
}

message GetByFilterResponse {
  Partner document = 1;
}
