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

syntax = "proto3";

package publishinguserpackage;

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

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

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

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

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

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

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

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

message GetByIdRequest {
  string id = 1;
}

message GetByIdResponse {
  PublishingUser document = 1;
}

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

message GetByIdsResponse {
  repeated PublishingUser 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 PublishingUser {
  string display_name = 1;
  string email = 2;
  string image = 3;
  bool active = 4;
  PublishingPermissions publishing_permissions = 5;
  string updated_at = 6;
  string created_at = 7;
  string id = 8;
}

message PublishingPermissions {
  Scheduling scheduling = 1;
  string role = 2;
}

message Scheduling {
  repeated string read = 1;
  repeated string write = 2;
}

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

message UpdateFieldsResponse {
  PublishingUser document = 1;
}
