syntax = "proto3";
package conio.sdk.v1;


message ConioCredentials {
    string externalUserID = 1;
    string hashedConioPassword = 2;
}

enum AcceptanceType {
  __ACCEPTANCE_DO_NOT_USE = 0;
  ACCEPTANCE_CLIENT_SUPPORT = 1;
  ACCEPTANCE_APP_IMPROVEMENT = 2;
}

enum AcceptanceChoiceType {
  __ACC_CHOICE_DO_NOT_USE = 0;
  ACC_CHOICE_ACCEPTED = 1;
  ACC_CHOICE_REJECTED = 2;
}

message Acceptance {
  string acceptance_type = 1;
  AcceptanceChoiceType acceptance_choice = 2;
}

message TermsAndConditionsAcceptances {
    repeated Acceptance acceptances = 1;
}

message SignupCryptoRequest {
    string proofID = 1;
    bytes cryptoProof = 2;
    uint64 proofExpiration = 3;
    string externalUserID = 4;
    string userLevel = 5;
    string iban = 6;
    string email = 7;
    string firstName = 8;
    string lastName = 9;
}

message EncryptedUserKey {
    bytes encryptedMnemonic = 1;
    bytes encryptedSeed = 2;
    bytes encryptedPrivateKey = 3;
    string bip32PublicKey = 4;
}

message Signup {
    ConioCredentials conioCredentials = 1;
    TermsAndConditionsAcceptances tc = 2;
    SignupCryptoRequest cryptoRequest = 3;
    EncryptedUserKey encryptedUserKey = 4;
}

message SignupResponse {
    TermsAndConditionsAcceptances tc = 1;
    EncryptedUserKey encryptedUserKey = 2;
}

message Login {
    ConioCredentials conioCredentials = 1;
}

message LoginResponse {
    TermsAndConditionsAcceptances tc = 1;
    EncryptedUserKey encryptedUserKey = 2;
}

message WalletInfo {
    uint64 confirmed_satoshi_amount = 1;
    uint64 unconfirmed_satoshi_amount = 2;
    // Not necessary by itself but prevents serialization from producing
    // empty strings, which are translated by AWS into b'no data'
    uint64 timestamp = 3;
}

message CurrentBtcAddress {
    string btc_address_id = 1;
}

message MsgRequestBtcWithdrawal {
  string dest_address = 1;
  uint64 amount = 2;
  uint64 fee_per_byte = 4;
}

message TransactionSignData {
  repeated uint32 path = 1;
  bytes data_to_sign = 2;
}

message MsgRequestBtcWithdrawalResponse {
    bytes tx = 1;
    uint64 date = 2;
    bytes signature = 3;
    repeated TransactionSignData sign_data = 4;
    uint64 fees = 5;
}

message Signature {
  repeated uint32 path = 1;
  bytes signature = 2;
}

message MsgWithdrawBtc {
  bytes tx = 1;
  uint64 date = 2;
  bytes request_signature = 3;
  repeated Signature tx_signatures = 5;
}

message MsgWithdrawBtcResponse {
  string activity_id = 1;
}


enum ActivityType {
  __ACTIVITY_TYPE_DO_NOT_USE = 0;
  ACTIVITY_SELL = 1;
  ACTIVITY_BUY = 2;
  ACTIVITY_SEND = 3;
  ACTIVITY_RECV = 4;
}

enum BidStatus {
  __BID_STATUS_DO_NOT_USE = 0;
  BID_CREATED = 1;
  BID_PAID = 2;
  BID_CHARGED = 3;
  BID_ERROR = 4;
  BID_UNKNOWN = 5;
}

enum CurrencyCode {
  EUR = 0;
  USD = 1;
}

message Bid {
  string id = 1;  // required
  BidStatus status = 2;  // required
  uint64 satoshi = 3;  // required
  float fiat_amount = 4;  // required
  CurrencyCode currency = 5;  // required
  uint64 created_at = 6;  // required
  uint64 updated_at = 7;  // optional
  string payment_id = 8;  // optional
  double fee = 9;  // required
}

enum AskStatus {
  __ASK_STATUS_DO_NOT_USE = 0;
  ASK_CREATED = 1;
  ASK_PAID = 2;
  ASK_CHARGED = 3;
  ASK_ERROR = 4;
  ASK_UNKNOWN = 5;
}

message Ask {
  string id = 1;  // required
  AskStatus status = 2;  // required
  uint64 satoshi = 3;  // required
  float fiat_amount = 4;  // required
  CurrencyCode currency = 5;  // required
  uint64 created_at = 6;  // required
  uint64 updated_at = 7;  // optional
  double fee = 9;  // required
}

enum SellStatus {
    __SELL_STATUS_DO_NOT_USE = 0;
    INIT = 1;
    SETTLED = 2;
}

message Sell {
    string id = 1;  // required
    string sell_method_id = 2;  // required
    SellStatus status = 3;  // required
    string cro = 4;  // optional
    string iban = 5;  // optional
}

message Activity {
  ActivityType activity_type = 1;  // required
  Transaction transaction = 2;  // optional
  Bid bid = 3;  // optional
  CardIntegrationPayment payment = 4;  // optional
  string activity_id = 5;  // required
  uint64 timestamp = 6;  // required
  Ask ask = 7;  // optional
  Sell sell = 8;  // optional
}

message SimpleActivity {
    ActivityType activity_type = 1;  // required
    string activity_id = 2;  // required
    uint64 timestamp = 3;  // required
    uint64 satoshi = 4;  // required
    float fiat_amount = 5;  // required
    bool can_be_spent = 6;  // required
    bool has_been_accelerated = 7;  // required
    TransactionStatus status = 8;  // optional
}

message MsgActivitiesInfo {
  uint32 from_index = 1;  // required
  bool get_previous = 2;  // required
  repeated ActivityType activity_types = 3;
  string fiat = 4;  // required
}

message MsgActivityDetails {
  string activity_id = 1;  // required
  string fiat_currency = 2;  // required
}

message MsgActivitiesInfoResponse {
  repeated SimpleActivity activities = 1;
}

enum TransactionStatus {
  __TRANSACTION_STATUS_DO_NOT_USE = 0;
  UNCONFIRMED = 1;
  PARTIALLY_CONFIRMED = 2;
  CONFIRMED = 3;
  REMOVED = 4;
  ACCELERATED = 5;
}

enum TransactionType {
  TRANSACTION_TYPE_GENERIC = 0;
  TRANSACTION_TYPE_CPFP_CHILD = 1;
  TRANSACTION_TYPE_CPFP_PARENT = 2;
  TRANSACTION_TYPE_REDEPOSIT = 3;
  TRANSACTION_TYPE_RBF = 4;
}

message Transaction {
  string hash = 1;  // required
  uint64 amount = 2;  // required
  uint64 timestamp = 3;  // required
  repeated string recipients = 4;
  TransactionStatus status = 5;  // required
  bool incoming = 6;  // required
  repeated string senders = 7;
  double fiat = 8;  // required
  int32 height = 9;  // required
  bool spent = 10;  // required
  uint32 confirmations = 11;  // required
  uint64 fees = 12;  // required
  uint64 included_at = 13;  // optional
  uint64 confirmed_at = 14;  // optional
  TransactionType type = 15;  // optional
  int32 fee_per_byte = 16;  // required
  string parent = 17;  // optional
  repeated string wallet_recipients = 18;
  bool is_local = 19;  // optional
}

message CardIntegrationPayment {
  string id = 1;  // required
  CardIntegrationPaymentStatus status = 2;  // required
  uint64 created_at = 3;  // required
  uint64 updated_at = 4;  // optional
  double amount = 5;  // required
  string currency = 6;  // required
  string paymentmethod_id = 7;  // optional
}

enum CardIntegrationPaymentStatus {
  __CARD_INTEGRATION_PAYMENT_STATUS__DO_NOT_USE = 0;
  PROCESSING = 1;
  CANCELLED = 2;
  COMPLETED = 3;
  ERROR = 4;
  REFUND = 5;
}


enum TransactionSpeedType {
  __TRANSACTION_SPEED_TYPE_DO_NOT_USE = 0;
  TRANSACTION_SPEED_TYPE_1 = 1;
  TRANSACTION_SPEED_TYPE_2 = 2;
  TRANSACTION_SPEED_TYPE_3 = 3;
  TRANSACTION_SPEED_TYPE_4 = 4;
  TRANSACTION_SPEED_TYPE_5 = 5;
}


message MsgRequestBtcWithdrawalFees {
  string dest_address = 1;  // required
  uint64 amount = 2;  // optional
  oneof payload {
    TransactionSpeedType speed = 3; // optional
    bool get_all_fees_info = 4; // optional
  }
}


message TransactionSpeed {
  TransactionSpeedType type = 1;  // required
  uint64 min_time = 2;  // required
  uint64 max_time = 3;  // required
}


message FeeDetails {
  uint64 fee_per_byte = 1;  // required
  uint64 speed = 2;  // required
  uint64 min_time = 3;  // required
  uint64 max_time = 4;  // required
  uint64 absolute_fee = 5;  // required
  uint64 amount = 6;  // required
}

message MsgRequestBtcWithdrawalFeesResponse {
  uint64 absolute_fees = 1;  // required
  uint64 amount = 2;  // required
  uint64 fee_per_byte = 3;  // required
  TransactionSpeed transaction_speed = 4;  // required
  uint64 absolute_fees_fiat = 5;  // optional
  repeated FeeDetails available_fees = 6;
}

message MsgGetCurrentPrice {
    CurrencyCode currency = 1;
    uint64 satoshi_amount = 2;  // optional
}

message PricePoint {
    double buy_price = 1;
    double sell_price = 2;
    uint64 timestamp = 3;
}

message MsgHistoryPrices {
  CurrencyCode currency = 1;  // required
  uint64 start_timestamp = 2;  // required
  uint64 end_timestamp = 3;  // required
  uint64 interval = 4;  // optional
}

enum PriceTrend {
    __PRICE_TREND_DO_NOT_USE = 0;
    PRICE_TREND_RISING = 1;
    PRICE_TREND_FALLING = 2;
    PRICE_TREND_STAGNANT = 3;
}

message PriceAnalytics {
    PriceTrend trend = 1; // required
    double delta_fiat = 2; // required
    double delta_percentage = 3; // required
}

message MsgHistoryPricesResponse {
    repeated PricePoint price_points = 1;
    PriceAnalytics price_analytics = 2; // required
}

message MsgCreateOrRefreshAsk {
  string ask_id = 1;  // optional
  CurrencyCode currency = 2;  // required
  oneof payload {
    uint64 satoshi = 3;
    double fiat_amount = 4;
  }
}

message MsgCreateOrRefreshAskResponse {
  string ask_id = 1;  // required
  uint64 satoshi = 2;  // required
  double fiat_amount = 3;  // required
  CurrencyCode currency = 4;  // required
  uint64 expiration_timestamp = 5;  // required
  double fee = 6;  // required
  uint64 miner_fee = 7;  // required
}

message MsgPayForAsk {
  string ask_id = 1;  // required
}

message MsgPayForAskResponse {
  string ask_id = 1;  // required
  bytes tx = 2;  // required
  uint64 date = 3;  // required
  bytes request_signature = 4;  // required
  repeated TransactionSignData sign_data = 5;
  uint64 fees = 6;  // required
}

message MsgFinalizePaymentForAsk {
  string ask_id = 1;  // required
  bytes tx = 2;  // required
  repeated Signature signatures = 3;
  uint64 date = 4;  // required
  bytes request_signature = 5;  // required
}

// I need a non-empty response message just to avoid the b'no data' from API GW.
message MsgFinalizePaymentForAskResponse {
    string ask_id = 1;  // required
}

message MsgCreateOrRefreshBid {
  string bid_id = 1;  // optional
  CurrencyCode currency = 2;  // required
  oneof payload {
    uint64 satoshi = 3;
    double fiat_amount = 4;
  }
}

message MsgCreateOrRefreshBidResponse {
    message WiretransferPayeeInfo {
        string description = 1;  // required since version 1.1
        string holder = 2;  // required since version 1.1
        string holder_iban = 3;  // required since version 1.1
    }
    string bid_id = 1;  // required
    uint64 satoshi = 2;  // required
    double fiat_amount = 3;  // required
    CurrencyCode currency = 4;  // required
    uint64 expiration_timestamp = 5;  // required
    double fee = 6;  // required
    WiretransferPayeeInfo wiretransfer_payee_info = 7;  // required since version 1.1
}

message PayForBidCryptoRequest {
  string proofID = 1;  // required
  bytes cryptoProof = 2;  // required
  uint64 proofExpiration = 3;  // required
  // string externalUserID = 4;
  string external_reference_id = 4;  // required
}

message MsgPayForBid {
  string bid_id = 1;  // required
  PayForBidCryptoRequest crypto_proof = 2;  // required
}

message MsgPayForBidResponse {
  string bid_id = 1;  // required
  string maskedpan = 2;  // optional
  string payment_token = 3;  // required
  string gp_id = 4; // required
  string gp_url = 5;  // required
}

message PayForBidWTCryptoRequest {
  string proofID = 1;  // required
  bytes cryptoProof = 2;  // required
  uint64 proofExpiration = 3;  // required
}

message MsgPayForBidUsingWiretransferResponse {
    string bid_id = 1; // required
}

message MsgPayForBidUsingWiretransfer {
  string bid_id = 1;  // required
  PayForBidWTCryptoRequest crypto_proof = 2;  // required
}

message MsgFinalizeBidUsingWiretransfer {
    string bid_id = 1;
}

message MsgFinalizeBidUsingWiretransferResponse {
    string bid_id = 1; // required
}

message MsgFinalizePaymentForBid {
    string bid_id = 1; // required
    string maskedpan = 2; // optional
    PayForBidCryptoRequest crypto_proof = 3;  // required
}

message MsgFinalizePaymentForBidResponse {
    string bid_id = 1; // required
}

message MsgFinalizePaymentForBidUsingWiretransfer {
    string bid_id = 1; // required
}

message MsgFinalizePaymentForBidUsingWiretransferResponse {
    string bid_id = 1; // required
}

enum FiatLimitType {
  __FIAT_LIMIT_TYPE_DO_NOT_USE = 0;
  MONTHLY = 1;
  DAILY = 2;
  YEARLY = 3;
}

message FiatLimit {
  FiatLimitType limit_type = 1;  // required
  double limit = 2;  // required
}

message TradingFiatLimits {
  double current_limit = 1;  // required
  repeated FiatLimit all_limits = 2;
  repeated FiatLimit current_limits_by_type = 3;
}

message MsgGetTradingLimitsResponse {
    TradingFiatLimits buy_fiat_limits = 1;  // required
    TradingFiatLimits sell_fiat_limits = 2;  // required
    double buy_min_fiat_limits = 3;  // required
    double sell_min_fiat_limits = 4;  // required
}

message TermsAndConditionsAndPrivacyPolicy {
    message AcceptanceDetail {
        string acceptance_type = 1;
        string i18n_text_title = 2;
        string i18n_text_body = 3;
        bool mandatory = 4;
    }
    string terms_and_conditions_url = 1;
    string privacy_policies_url = 2;
    repeated AcceptanceDetail acceptances = 3;
}
