syntax = "proto3";

// Внутренний gRPC deposit_service (ончейн-депозиты, payment-dill-deposit, BitGo ack).
package deposit.v1;

option csharp_namespace = "Deposit.V1";
option java_multiple_files = true;
option java_package = "com.arbiwallet.deposit.v1";

service DepositIntegration {
  // Привязать событие BitGo к уже найденному ончейн-депозиту (mpc webhook).
  rpc ApplyBitGoCustodyAck(ApplyBitGoCustodyAckRequest) returns (ApplyBitGoCustodyAckResponse);

  // Пополнение через payment microservice (ARBIPAY): RUB SBP / USDT.
  rpc CreatePaymentDillDeposit(CreatePaymentDillDepositRequest) returns (CreatePaymentDillDepositResponse);

  rpc HandlePaymentDillDepositWebhook(HandlePaymentDillDepositWebhookRequest)
      returns (HandlePaymentDillDepositWebhookResponse);

  rpc GetPaymentDillDepositStatus(GetPaymentDillDepositStatusRequest)
      returns (GetPaymentDillDepositStatusResponse);
}

message ApplyBitGoCustodyAckRequest {
  string network = 1;              // TRON | BSC
  string tx_hash = 2;
  optional int32 log_index = 3;
  string bitgo_transfer_id = 4;
  string bitgo_state = 5;
  string webhook_event_id = 6;     // может быть пустым
}

message ApplyBitGoCustodyAckResponse {
  int32 matched = 1;
  repeated string deposit_tx_ids = 2;
}

message CreatePaymentDillDepositRequest {
  string user_id = 1;
  /** USDT to credit (major units), e.g. "100.50" */
  string amount = 2;
  /** Pay-in: RUB (SBP) | USDT (crypto) */
  string payment_currency = 3;
  /** Зачисление в Ledger (по умолчанию USDT) */
  optional string credit_asset = 4;
  /** Сеть баланса в Ledger (по умолчанию TRON) */
  optional string credit_network = 5;
  /** WALLET_TOPUP | CARD_TOPUP */
  optional string purpose = 6;
  /** JSON payload for downstream orchestration (e.g. card top-up). */
  optional string purpose_payload_json = 7;
}

message CreatePaymentDillDepositResponse {
  string deposit_id = 1;
  string status = 2;
  optional string payment_url = 3;
  optional string crypto_wallet = 4;
  optional string qr_link = 5;
  optional string redirect_url = 6;
  optional string provider_transaction_id = 7;
  /** Exact pay-in amount in major units from provider quote. */
  optional string pay_amount = 14;
  /** Pay-in amount in minor units (from payment microservice) */
  optional string amount_minor = 8;
  /** Pay-in currency (RUB | USDT) */
  optional string payment_currency = 9;
  /** USDT to credit (requested / quoted output) */
  optional string credit_amount = 10;
  optional string requested_credit_amount = 13;
  optional string credit_asset = 11;
  optional string credit_network = 12;
}

message HandlePaymentDillDepositWebhookRequest {
  string json_payload = 1;
}

message HandlePaymentDillDepositWebhookResponse {
  bool ok = 1;
  string deposit_id = 2;
  string status = 3;
}

message GetPaymentDillDepositStatusRequest {
  string user_id = 1;
  string deposit_id = 2;
}

message GetPaymentDillDepositStatusResponse {
  string deposit_id = 1;
  string status = 2;
  optional string payment_currency = 3;
  optional string purpose = 4;
  optional string requested_credit_amount = 5;
  optional string amount_major = 6;
  optional string credit_amount = 7;
  optional string credit_asset = 8;
  optional string credit_network = 9;
  optional string provider_transaction_id = 10;
  optional string ledger_deposit_id = 11;
  optional string card_topup_status = 12;
  optional string card_topup_error = 13;
  optional string card_create_status = 14;
  optional string card_create_error = 15;
  optional int64 created_card_id = 16;
  optional string created_at = 17;
  optional string completed_at = 18;
  optional string expires_at = 19;
  optional string expired_at = 20;
  optional string payout_status = 21;
  optional string payout_error = 22;
  optional int64 payout_id = 23;
}
