/*
 * Created by jonathan.jesperson@pluto.tv on 11/11/2022.
 * Copyright (c) PlutoTV Inc 2022.
 */

syntax = "proto3";

package gracenotelogspackage;

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

service GracenoteLogsManager {
  // CFeedsSyncDocuments (Server Stream)
  //
  rpc CFeedsSyncDocuments(CFeedsSyncDocumentsRequest) returns (stream GracenoteLog) {}

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

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 GracenoteLog {
  string id = 1;
  string item_type = 2;
  string item_id = 3;
  string tmsid = 4;
  bool warning = 5;
  repeated string details = 6;

  TmsIds tms_ids = 7;
  Counts counts = 8;
  bool summary = 9;
  string active_region = 10;
  int32 day_key = 11;
  // map because this is keyed by country code, which may change
  map<string, TmsItemCountry> tms_items = 12;
  Metrics metrics = 13;
  string updated_at = 14;
  string created_at = 15;
}

message TmsItemCountry {
  int64 movies = 1;
  int64 movies_a_v_o_d = 2;
  int64 series = 3;
  int64 series_a_v_o_d = 4;
  int64 episodes = 5;
  int64 episodes_a_v_o_d = 6;
}

message TmsIds {
  TmsIdCounts series = 1;
  TmsIdCounts episodes = 2;
}

message TmsIdCounts {
  int64 total_count = 1;
  int64 tms_count = 2;
}

message Counts {
  TotalCount gracenote_runs = 1 [json_name = "gracenote-runs"];
  TotalCount gracenote_logs = 2 [json_name = "gracenote-logs"];
  TotalCount gracenote_metadata = 3 [json_name = "gracenote-metadata"];
}

message TotalCount {
  int64 total_count = 1;
}

message Metrics {
  Breakdown tv = 1;
  Breakdown film = 2;
}

message Breakdown {
  // map because this is keyed by country code, which may change
  map<string, MetricCountryStatus> _s_t_b = 1 [json_name = "STB"];
  map<string, MetricCountryStatus> _v_o_d = 2 [json_name = "VOD"];
  map<string, TotalAvCountryMetrics> _total_a_v = 3 [json_name = "TotalAV"];
  map<string, TmsCountryMetrics> _series_t_m_s = 4 [json_name = "SeriesTMS"];
  map<string, TmsCountryMetrics> _episodes_with_t_m_s = 5 [json_name = "EpisodesWithTMS"];
  map<string, EpisodesGroupedCountryMetrics> _episodes_grouped = 6 [json_name = "EpisodesGrouped"];
}

message MetricCountryStatus {
  int64 archived = 1;
  int64 completed = 2;
  int64 in__progress = 3 [json_name = "in progress"];
  int64 on__air = 4 [json_name = "on air"];
  int64 total = 5;
}

message TotalAvCountryMetrics {
  int64 notavailable = 1;
  int64 available = 2;
  int64 total = 3;
}

message TmsCountryMetrics {
  int64 total = 1;
  int64 matched = 2;
}

message EpisodesGroupedCountryMetrics {
  // map because this is keyed by country code, which may change
  map<string, int64> archived = 1;
  map<string, int64> completed = 2;
  map<string, int64> in__progress = 3 [json_name = "in progress"];
  map<string, int64> on__air = 4 [json_name = "on air"];
}
