syntax = "proto3";

import "google/protobuf/timestamp.proto";
package code.justin.tv.commerce.phanto;
option go_package = "phanto";

// Supported Endpoints

service Phanto {
  rpc HealthCheck (HealthCheckReq) returns (HealthCheckResp) {};
  rpc CreateProductType (CreateProductTypeReq) returns (CreateProductTypeResp) {};
  rpc CreateProduct (CreateProductReq) returns (CreateProductResp) {};
  rpc CreateKeyPool (CreateKeyPoolReq) returns (CreateKeyPoolResp) {};
  rpc GenerateKeyBatch (GenerateKeyBatchReq) returns (GenerateKeyBatchResp) {};
  rpc GetKeyBatchStatus (GetKeyBatchStatusReq) returns (GetKeyBatchStatusResp) {};
  rpc GetKeyBatchDownloadInfo (GetKeyBatchDownloadInfoReq) returns (GetKeyBatchDownloadInfoResp) {};
  rpc GetKeyStatus (GetKeyStatusReq) returns (GetKeyStatusResp) {};
  rpc RedeemKey (RedeemKeyReq) returns (RedeemKeyResp) {};
  rpc InvalidateKeys (InvalidateKeysReq) returns (InvalidateKeysResp) {};
  rpc InvalidateKeyBatch (InvalidateKeyBatchReq) returns (InvalidateKeyBatchResp) {};
  rpc InvalidateKeyPool (InvalidateKeyPoolReq) returns (InvalidateKeyPoolResp) {};
  rpc GetAllKeyPools (GetAllKeyPoolsReq) returns (GetAllKeyPoolsResp) {};
  rpc GetKeyBatches (GetKeyBatchesReq) returns (GetKeyBatchesResp) {};
  rpc GetKeyBatchesS2S (GetKeyBatchesReq) returns (GetKeyBatchesResp) {};
  rpc GetKeyPoolsByHandler (GetKeyPoolsByHandlerReq) returns (GetKeyPoolsByHandlerResp) {};
  rpc GetAllProductTypes (GetAllProductTypesReq) returns (GetAllProductTypesResp) {};
  rpc GetProducts (GetProductsReq) returns (GetProductsResp) {};
  rpc GetKeyPoolReports (GetKeyPoolReportsReq) returns (GetKeyPoolReportsResp) {};
  rpc GenerateKeyPoolReport (GenerateKeyPoolReportReq) returns (GenerateKeyPoolReportResp) {};
  rpc GetKeyPoolReportDownloadInfo (GetKeyPoolReportDownloadInfoReq) returns (GetKeyPoolReportDownloadInfoResp) {};
}

message HealthCheckReq {
}

message HealthCheckResp {
}

message GenerateKeyBatchReq {
  string batch_id = 1;
  string pool_id = 2;
  int64 number_of_keys = 3;
}

message GenerateKeyBatchResp {
  string batch_id = 1;
}

message GetKeyBatchStatusReq {
  string batch_id = 1;
}

message GetKeyBatchStatusResp {
  string status = 1;
  string workflow_status = 2;
  double progress = 3;
}

message GetKeyBatchDownloadInfoReq {
  string batch_id = 1;
}

message GetKeyBatchDownloadInfoResp {
  string download_url = 1;
  string decryption_key = 2;
}

message GetKeyStatusReq {
  string key = 1;
}

message GetKeyStatusResp {
  string product_type = 1;
  string sku = 2;
  string description = 3;
  string batch_id = 4;
  string pool_id = 5;
  string status = 6;
}

message RedeemKeyReq {
  string key = 1;
  string user_id = 2;
  string client_ip = 3;
}

message RedeemKeyResp {
}

message InvalidateKeysReq {
  repeated string keys = 1;
}

message InvalidateKeysResp {
}

message InvalidateKeyBatchReq {
  string batch_id = 1;
}

message InvalidateKeyBatchResp {
}

message InvalidateKeyPoolReq {
  string pool_id = 1;
}

message InvalidateKeyPoolResp {
}

message CreateProductTypeReq {
  string product_type = 1;
  string sns_topic = 2;
  string description = 3;
}

message CreateProductTypeResp {

}

message CreateProductReq {
  string product_type = 1;
  string sku = 2;
  string description = 3;
}

message CreateProductResp {
}

message CreateKeyPoolReq {
  string pool_id = 1;
  string product_type = 2;
  string sku = 3;
  string description = 4;
  string handler = 5;
  google.protobuf.Timestamp start_date = 6;
  google.protobuf.Timestamp end_date = 7;
}

message CreateKeyPoolResp {
}

message KeyPool {
  string product_type = 1;
  string sku = 2;
  string description = 3;
  string pool_id = 4;
  string status = 5;
  string handler = 6;
  google.protobuf.Timestamp start_date = 7;
  google.protobuf.Timestamp end_date = 8;

}

message KeyBatch {
  string pool_id = 1;
  string batch_id = 2;
  int64 number_of_keys = 3;
  string status = 4;
  string workflow_status = 5;
}

message GetAllKeyPoolsReq {
  string cursor = 1;
}

message GetAllKeyPoolsResp {
  repeated KeyPool key_pools = 1;
  string cursor = 2;
}

message GetKeyBatchesReq {
  string pool_id = 1;
  string cursor = 2;
}

message GetKeyBatchesResp {
  repeated KeyBatch key_batches = 1;
  string cursor = 2;
}

message GetKeyPoolsByHandlerReq {
  string handler = 1;
  string cursor = 2;
}

message GetKeyPoolsByHandlerResp {
  repeated KeyPool key_pools = 1;
  string cursor = 2;
}

message ProductType {
  string product_type = 1;
  string sns_topic = 2;
  string description = 3;
}

message GetAllProductTypesReq {
  string cursor = 1;
}

message GetAllProductTypesResp {
  repeated ProductType product_types = 1;
  string cursor = 2;
}

message Product {
  string product_type = 1;
  string sku = 2;
  string description = 3;
}

message GetProductsReq {
  string product_type = 1;
  string cursor = 2;
}

message GetProductsResp {
  repeated Product products = 1;
  string cursor = 2;
}

message GetKeyPoolReportsReq {
  string pool_id = 1;
  string cursor = 2;
}

message GetKeyPoolReportsResp {
  repeated KeyPoolReport key_pool_reports = 1;
  string cursor = 2;
}

message KeyPoolReport {
  string pool_id = 1;
  string report_id = 2;
  google.protobuf.Timestamp requested_at = 3;
  string requested_by = 4;
  string status = 5;
}

message GenerateKeyPoolReportReq {
  string pool_id = 1;
}

message GenerateKeyPoolReportResp {
  string pool_id = 1;
  string report_id = 2;
}

message GetKeyPoolReportDownloadInfoReq {
  string report_id = 1;
}

message GetKeyPoolReportDownloadInfoResp {
  string download_url = 1;
  string decryption_key = 2;
}