syntax = "proto3";

package delivery;
option go_package = "github.com/Ogury/ms-auction/grpc/ogury/delivery";

/*
 * Priority section to get priorities of campaigns
 */
service Campaigns {
  rpc GetPriorities (Request) returns (Response) {
  }
  rpc GetSpeed (Request) returns (SpeedResponse) {
  }
  rpc GetIsolatedSpeed (Request) returns (IsolatedSpeedResponse) {
  }
  rpc GetRecommender (Request) returns (RecommenderResponse) {
  }
}

message Request {
  string id = 1;
  repeated Campaign campaigns = 2;
  User user = 3;
  Device device = 4;
  App app = 5;
  Context context = 6;
}

message Campaign {
  string id = 1;
  repeated string category_iab = 2;
  bool eula = 3;
}

message User {
  string odid = 1;
  bool data_optin = 2;
}

message Device {
  string name = 1;
  string os_version = 2;
  string connectivity = 3;
  string isp = 4;
  string ifa = 5;
  string ua = 6;
  string language = 7;
  string ip = 8;
  string os = 9;
}

message App {
  string bundle_id = 1;
  string name = 2;
  repeated string cat = 3;
  string app_api_key = 4;
  string ad_unit_id = 5;
  int32 app_publisher_id = 6;
  int32 eecpm = 7;
}

message Context {
  int32 day_of_week = 1;
  int32 hour = 2;
  string city = 3;
  string ssp = 4;
  string country = 5;
}

message Response {
  string id = 1;
  repeated CampaignResult campaigns = 2;
}

message CampaignResult {
  string id = 1;
  float score = 2;
  map<string, string> metadata = 3;
}

message MultipleCampaignsResult {
  repeated CampaignResult campaigns = 1;
}

/*
* ms-speed specifics
*/

message SpeedResponse {
  int32 id = 1;
  repeated SpeedCampaignResult campaigns = 2;
}

message SpeedCampaignResult {
  string id = 1;
  reserved 2; // deprecated field "selected"
  SpeedCampaignMetadata metadata = 3;
}

message IsolatedSpeedResponse {
  int32 id = 1;
  string experiment_name = 2;
  repeated IsolatedSpeedCampaignResult campaigns = 3;
}

message IsolatedSpeedCampaignResult {
  string id = 1;
  repeated SpeedCampaignMetadata pops_metadata = 2;
}

message SpeedCampaignMetadata {
  string delay = 1;
  reserved 2; // deprecated field "ponderation"
  string threshold = 3;
}

/*
* Recommender specifics
*/

message RecommenderResponse {
  string id = 1;
  repeated RecommenderCampaignResult campaigns = 2;
  float difference = 3;
  float bound_lower = 4;
  float bound_upper = 5;
  float app_eecpm = 6;
  float app_ecpm = 7;
}

message RecommenderCampaignResult {
  string id = 1;
  bool selected = 2;
  map<string, string> metadata = 3;
}

/*
 * Server section for Health check & co
 */
service Server {
  rpc CheckHealth (Ping) returns (Pong) {
  }
}

message Ping {
  string id = 1;
}

message Pong {
  string id = 1;
}
