syntax = "proto3";

package cdk_payment_processor;

service CdkPaymentProcessor {  
    rpc GetSettings(EmptyRequest) returns (SettingsResponse) {}
    rpc CreatePayment(CreatePaymentRequest) returns (CreatePaymentResponse) {}
    rpc GetPaymentQuote(PaymentQuoteRequest) returns (PaymentQuoteResponse) {}
    rpc MakePayment(MakePaymentRequest) returns (MakePaymentResponse) {}
    rpc CheckIncomingPayment(CheckIncomingPaymentRequest) returns (CheckIncomingPaymentResponse) {}
    rpc CheckOutgoingPayment(CheckOutgoingPaymentRequest) returns (MakePaymentResponse) {}
    rpc WaitIncomingPayment(EmptyRequest) returns (stream WaitIncomingPaymentResponse) {}
}

message EmptyRequest {}

message SettingsResponse {
  string inner = 1;
}

message Bolt11IncomingPaymentOptions {
  optional string description = 1;
  uint64 amount = 2;
  optional uint64 unix_expiry = 3;
}

message Bolt12IncomingPaymentOptions {
  optional string description = 1;
  optional uint64 amount = 2;
  optional uint64 unix_expiry = 3;
}

enum PaymentMethodType {
  BOLT11 = 0;
  BOLT12 = 1;
}

enum OutgoingPaymentRequestType {
  BOLT11_INVOICE = 0;
  BOLT12_OFFER = 1;
}

enum PaymentIdentifierType {
  PAYMENT_HASH = 0;
  OFFER_ID = 1;
  LABEL = 2;
  BOLT12_PAYMENT_HASH = 3;
  CUSTOM_ID = 4;
  PAYMENT_ID = 5;
}

message PaymentIdentifier {
  PaymentIdentifierType type = 1;
  oneof value {
    string hash = 2; // Used for PAYMENT_HASH and BOLT12_PAYMENT_HASH
    string id = 3;   // Used for OFFER_ID, LABEL, and CUSTOM_ID
  }
}

message IncomingPaymentOptions {
  oneof options {
    Bolt11IncomingPaymentOptions bolt11 = 1;
    Bolt12IncomingPaymentOptions bolt12 = 2;
  }
}

message CreatePaymentRequest {
  string unit = 1;
  IncomingPaymentOptions options = 2;
}

message CreatePaymentResponse {
  PaymentIdentifier request_identifier = 1;
  string request = 2;
  optional uint64 expiry = 3;
}

message Mpp {
    uint64 amount = 1;
}

message Amountless {
    uint64 amount_msat = 1;
}

message MeltOptions {
    oneof options {
        Mpp mpp = 1;
        Amountless amountless = 2;
    }
}

message PaymentQuoteRequest {
  string request = 1;
  string unit = 2;
  optional MeltOptions options = 3;
  OutgoingPaymentRequestType request_type = 4;
}

enum QuoteState {
    UNPAID = 0;
    PAID = 1;
    PENDING = 2;
    UNKNOWN = 3;
    FAILED = 4;
    ISSUED = 5;
}


message PaymentQuoteResponse {
  PaymentIdentifier request_identifier = 1;
  uint64 amount = 2;
  uint64 fee = 3;
  QuoteState state = 4;
  string unit = 5;
}

message Bolt11OutgoingPaymentOptions {
  string bolt11 = 1;
  optional uint64 max_fee_amount = 2;
  optional uint64 timeout_secs = 3;
  optional MeltOptions melt_options = 4;
}

message Bolt12OutgoingPaymentOptions {
  string offer = 1;
  optional uint64 max_fee_amount = 2;
  optional uint64 timeout_secs = 3;
  optional MeltOptions melt_options = 5;
}

enum OutgoingPaymentOptionsType {
  OUTGOING_BOLT11 = 0;
  OUTGOING_BOLT12 = 1;
}

message OutgoingPaymentVariant {
  oneof options {
    Bolt11OutgoingPaymentOptions bolt11 = 1;
    Bolt12OutgoingPaymentOptions bolt12 = 2;
  }
}

message MakePaymentRequest {
  OutgoingPaymentVariant payment_options = 1;
  optional uint64 partial_amount = 2;
  optional uint64 max_fee_amount = 3;
}

message MakePaymentResponse {
  PaymentIdentifier payment_identifier = 1;
  optional string payment_proof = 2;
  QuoteState status = 3;
  uint64 total_spent = 4;
  string unit = 5;
}

message CheckIncomingPaymentRequest {
  PaymentIdentifier request_identifier = 1;
}

message CheckIncomingPaymentResponse {
  repeated WaitIncomingPaymentResponse payments = 1;
}

message CheckOutgoingPaymentRequest {
  PaymentIdentifier request_identifier = 1;
}

message WaitIncomingPaymentResponse {
  PaymentIdentifier payment_identifier = 1;
  uint64 payment_amount = 2;
  string unit = 3;
  string payment_id = 4;
}
