syntax = "proto3";

package twitch.fulton.twitchzuko;
import "google/protobuf/timestamp.proto";

option go_package = "code.justin.tv/amzn/TwitchZukoTwirp";


enum PinStatus {
    ACTIVE = 0;
    INVALID_PIN = 1;
    ALREADY_REDEEMED = 2;
}

enum UserRedeemStatus {
    REDEMPTION_SUCCESS = 0;
    REDEMPTION_INVALID_PIN = 1;
    REDEMPTION_ALREADY_REDEEMED = 2;
    EXCEEDED_WALLET_BALANCE = 3;
    TWO_FACTOR_REQUIRED = 4;
    INVALID_COUNTRY_OF_RESIDENCE = 5;
    EXCEEDED_VELOCITY_LIMIT = 6;
}

enum UserReverseStatus {
    REVERSAL_SUCCESS = 0;
    REVERSAL_INVALID_PIN = 1;
    REVERSAL_INVALID_TRANSACTION = 2;
}

message GetPinStatusRequest {
    string pin = 1;
    string user_id = 2;
}

message GetPinStatusResponse {
    string currency = 1;
    int64 amount_in_cents = 2;
    PinStatus status = 3;
}

message RedeemPinRequest {
    string pin = 1;
    string user_id = 2;
    string country_of_residence = 3;
    string tracking_session_id = 4;
}

message RedeemPinResponse {
    string currency = 1;
    int64 amount_in_cents = 2;
    UserRedeemStatus status = 3;
    string provider_transaction_id = 4;
}

message UnredeemPinRequest {
    string pin = 1;
    string provider_transaction_id = 2;
    string user_id = 3;
}

message UnredeemPinResponse {
    string currency = 1;
    int64 amount_in_cents = 2;
    UserReverseStatus status = 3;
}

message GetRedemptionHistoryRequest {
    string user_id = 1;
    string serial_number = 2;
    google.protobuf.Timestamp created_on_end = 3;
    google.protobuf.Timestamp created_on_start = 4;
}

message RedemptionRecord {
    string id = 1;
    string user_id = 2;
    int64 redeem_amount = 3;
    string currency = 4;
    string serial_number = 5;
    string redemption_status = 6;
    string vendor = 7;
    google.protobuf.Timestamp redemption_time = 8;
}

message GetRedemptionHistoryResponse {
    repeated RedemptionRecord redemption_history = 1;
}

service TwitchZuko {
    // Returns redemption status from Topps given a gift card pin
    rpc GetPinStatus (GetPinStatusRequest) returns (GetPinStatusResponse);

    // RedeemPin redeems a gift card into Twitch Wallet.
    rpc RedeemPin (RedeemPinRequest) returns (RedeemPinResponse);

    // Reverse a redemption. Used by CS
    rpc UnredeemPin (UnredeemPinRequest) returns (UnredeemPinResponse);

    // Get history of redemptions. Used by CS
    rpc GetRedemptionHistory (GetRedemptionHistoryRequest) returns (GetRedemptionHistoryResponse);
}