syntax = "proto3";
package invoice;

message e {}

service Invoice {
  rpc CreateNew(InvoiceForm) returns (NewInvoiceResponse);
  rpc GetById(ByIdRequest) returns (ByIdResponse);
  rpc GetByPurchaseId(PurchaseIdBulkRequest) returns (PurchaseIdBulkResponse);
  rpc Download(DownloadRequest) returns (DownloadResponse);
}

message InvoiceForm {
  message Customer {
    string id = 1;
    string name = 2;
    string tax_number = 3;
    string zip = 4;
    string location = 5;
    string street = 6;
    string email = 7;
  }
  message Item {
    string name = 1;
    int32 quantity = 2;
    string unit = 3;
    int32 price_unit_net = 4;
    string vat = 5;
    int32 total_price_net = 6;
    int32 total_price_vat = 7;
    int32 total_price_gross = 8;
    string comment = 9;
    // 10
  }
  string purchase_id = 1;
  Customer customer = 2;
  repeated Item items = 3;
  string payment_kind = 4; // cash, transfer, card
  string payment_duedate = 5; // Duedate if there any NOT RFC3339! e.g.: 2021-01-01 (NaiveDate)
  string date = 6; // NaiveDate
  string completion_date = 7; // NaiveDate
  int32 total_net = 8;
  int32 total_vat = 9;
  int32 total_gross = 10;
  string created_by = 11;
  // 11
}

message InvoiceData {
    string id = 1;
    string purchase_id = 2;
    string invoice_id = 3;
    string related_storno = 4;
    string created_by = 5;
    string created_at = 6;
}

message NewInvoiceResponse {
  InvoiceData invoice = 1;
}

message ByIdRequest {
  string id = 1;
}

message ByIdResponse {
  InvoiceData invoice = 1;
}

message PurchaseIdBulkRequest {
  string purchase_id = 1;
}

message PurchaseIdBulkResponse {
  repeated InvoiceData invoices = 1;
}

message DownloadRequest {
  string invoice_id = 1;
}

message DownloadResponse {
  string pdf_base64 = 1;
}