syntax = "proto3";
package cash;
import "google/protobuf/empty.proto";

message e {}

service Cash {
  // Create new transaction
  rpc CreateTransaction(NewTransaction) returns (TransactionObject);
  // Get transaction by id
  rpc GetById(ByIdRequest) returns (TransactionObject);
  // Get transacions bulk
  rpc GetBulk(BulkRequest) returns (stream TransactionObject);
  // Get current balance
  rpc GetBalance(google.protobuf.Empty) returns (BalanceObject);
  // Get transaction log by filter
  rpc GetByDateRange(DateRangeRequest) returns (TransactionIds);
}

message ByIdRequest { string transaction_id = 1; }

message BulkRequest { repeated string transaction_ids = 1; }

message TransactionIds { repeated string transaction_ids = 1; }

enum TransactionKind {
  KindCash = 0;
  KindCard = 1;
  KindTransfer = 2;
}

message NewTransaction {
  oneof cart_id {
    uint32 cart = 1;
    google.protobuf.Empty none = 2;
  }
  TransactionKind kind = 3;
  int32 amount = 4;
  string reference = 5;
  string comment = 6;
  uint32 created_by = 7;
}

message TransactionObject {
  string transaction_id = 1;
  oneof cart_id {
    uint32 cart = 2;
    google.protobuf.Empty none = 3;
  }
  TransactionKind kind = 4;
  int32 amount = 5;
  string reference = 6;
  string comment = 7;
  uint32 created_by = 8;
  string created_at = 9;
}

message BalanceObject { int32 balance = 1; }

message DateRangeRequest {
  // rfc3339
  string date_from = 1;
  // rfc3339
  string date_till = 2;
}