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

syntax = "proto3";

package ratingpackage;

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

service RatingManager {
  // GetDocumentsUpdatedBetweenDates (Server Stream)
  //
  rpc GetDocumentsUpdatedBetweenDates(GetDocumentsUpdatedBetweenDatesRequest) returns (stream Rating) {}

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

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

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

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 Rating {
  string id = 1;
  string value = 2;
  string region = 3;
  string weight = 4;
  string created_at = 5;
  string updated_at = 6;
  Symbol symbol = 7;
}

message Symbol {
  string path = 1;
}

message GetAllPagedSort {
  // field to sort on
  string field = 1;
  // sort direction 1 | -1
  int32 value = 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 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;
  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 GetAllPagedResponse {
  repeated Rating documents = 1;
  Metadata metadata = 2;
}
