proto/invoice -> bgpwtf/invoice/proto

Change-Id: I5d25864046665e4b0e57ec62a29797fbce6ed3cb
diff --git a/bgpwtf/invoice/BUILD.bazel b/bgpwtf/invoice/BUILD.bazel
index b2e2ee8..c85bb4d 100644
--- a/bgpwtf/invoice/BUILD.bazel
+++ b/bgpwtf/invoice/BUILD.bazel
@@ -12,10 +12,10 @@
     importpath = "code.hackerspace.pl/hscloud/bgpwtf/invoice",
     visibility = ["//visibility:private"],
     deps = [
+        "//bgpwtf/invoice/proto:go_default_library",
+        "//bgpwtf/invoice/templates:go_default_library",
         "//go/mirko:go_default_library",
         "//go/statusz:go_default_library",
-        "//bgpwtf/invoice/templates:go_default_library",
-        "//proto/invoice:go_default_library",
         "@com_github_golang_glog//:go_default_library",
         "@com_github_golang_protobuf//proto:go_default_library",
         "@com_github_mattn_go_sqlite3//:go_default_library",
diff --git a/bgpwtf/invoice/calc.go b/bgpwtf/invoice/calc.go
index 5df763f..9c411da 100644
--- a/bgpwtf/invoice/calc.go
+++ b/bgpwtf/invoice/calc.go
@@ -3,7 +3,7 @@
 import (
 	"time"
 
-	pb "code.hackerspace.pl/hscloud/proto/invoice"
+	pb "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto"
 )
 
 func calculateInvoiceData(p *pb.Invoice) {
diff --git a/bgpwtf/invoice/main.go b/bgpwtf/invoice/main.go
index 4a80441..d93034c 100644
--- a/bgpwtf/invoice/main.go
+++ b/bgpwtf/invoice/main.go
@@ -8,8 +8,8 @@
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 
+	pb "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto"
 	"code.hackerspace.pl/hscloud/go/mirko"
-	pb "code.hackerspace.pl/hscloud/proto/invoice"
 )
 
 var (
diff --git a/bgpwtf/invoice/model.go b/bgpwtf/invoice/model.go
index d628e1a..1fb89b9 100644
--- a/bgpwtf/invoice/model.go
+++ b/bgpwtf/invoice/model.go
@@ -13,7 +13,7 @@
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 
-	pb "code.hackerspace.pl/hscloud/proto/invoice"
+	pb "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto"
 )
 
 type model struct {
diff --git a/bgpwtf/invoice/proto/BUILD.bazel b/bgpwtf/invoice/proto/BUILD.bazel
index 511bf26..51f85fe 100644
--- a/bgpwtf/invoice/proto/BUILD.bazel
+++ b/bgpwtf/invoice/proto/BUILD.bazel
@@ -1,8 +1,23 @@
 load("@io_bazel_rules_go//go:def.bzl", "go_library")
+load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
+
+proto_library(
+    name = "proto_proto",
+    srcs = ["invoice.proto"],
+    visibility = ["//visibility:public"],
+)
+
+go_proto_library(
+    name = "proto_go_proto",
+    compilers = ["@io_bazel_rules_go//proto:go_grpc"],
+    importpath = "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto",
+    proto = ":proto_proto",
+    visibility = ["//visibility:public"],
+)
 
 go_library(
     name = "go_default_library",
-    srcs = ["generate.go"],
+    embed = [":proto_go_proto"],
     importpath = "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto",
     visibility = ["//visibility:public"],
 )
diff --git a/bgpwtf/invoice/proto/generate.go b/bgpwtf/invoice/proto/generate.go
deleted file mode 100644
index b0f6618..0000000
--- a/bgpwtf/invoice/proto/generate.go
+++ /dev/null
@@ -1,3 +0,0 @@
-package proto
-
-//go:generate protoc -I.. ../inboice.proto --go_out=plugins=grpc:.
diff --git a/bgpwtf/invoice/proto/invoice.proto b/bgpwtf/invoice/proto/invoice.proto
new file mode 100644
index 0000000..75720b7
--- /dev/null
+++ b/bgpwtf/invoice/proto/invoice.proto
@@ -0,0 +1,105 @@
+syntax = "proto3";
+package invoice;
+option go_package = "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto";
+
+message Item {
+    string title = 1;
+    uint64 count = 2;
+    uint64 unit_price = 3;
+    // in thousands of percent points
+    // (ie 23% == 23000)
+    uint64 vat = 4;
+    // Denormalized fields follow.
+    uint64 total_net = 5;
+    uint64 total = 6;
+}
+
+message ContactPoint {
+    string medium = 1;
+    string contact = 2;
+}
+
+message InvoiceData {
+    repeated Item item = 1;
+    repeated string invoicer_billing = 2;
+    repeated ContactPoint invoicer_contact = 3;
+    repeated string customer_billing = 4;
+    string invoicer_vat_id = 5;
+    string invoicer_company_number = 12;
+    string customer_vat_id = 6;
+    bool reverse_vat = 7;
+    bool us_customer = 11;
+    // Optional, if not given the proforma will be created with the current time.
+    int64 date = 14;
+    int64 days_due = 8;
+    string iban = 9;
+    string swift = 10;
+    string unit = 13;
+    // Next tag: 15
+}
+
+message Invoice {
+    // Original invoice parameters/data.
+    InvoiceData data = 1;
+    enum State {
+        STATE_INVALID = 0;
+        STATE_PROFORMA = 1;
+        STATE_SEALED = 2;
+    };
+    State state = 2;
+    string uid = 9;
+    // If sealed, otherwise 'proforma'.
+    string final_uid = 3;
+    int64 date = 4;
+    int64 due_date = 5;
+    // Denormalized fields follow.
+    uint64 total_net = 6;
+    uint64 total = 7;
+    string unit = 8;
+}
+
+message CreateInvoiceRequest {
+    InvoiceData invoice_data = 1;
+}
+
+message CreateInvoiceResponse {
+    // Unique invoice ID
+    string uid = 1;
+}
+
+message GetInvoiceRequest {
+    string uid = 1;
+}
+
+message GetInvoiceResponse {
+    Invoice invoice = 1;
+}
+
+message RenderInvoiceRequest {
+    string uid = 1;
+    string language = 2;
+}
+
+message RenderInvoiceResponse {
+    bytes data = 1;
+}
+
+message SealInvoiceRequest {
+    string uid = 1;
+    enum DateSource {
+        DATE_SOURCE_NOW = 0;
+        DATE_SOURCE_PROFORMA = 1;
+    }
+    DateSource date_source = 2;
+    string language = 3;
+}
+
+message SealInvoiceResponse {
+}
+
+service Invoicer {
+    rpc CreateInvoice(CreateInvoiceRequest) returns (CreateInvoiceResponse);
+    rpc GetInvoice(GetInvoiceRequest) returns (GetInvoiceResponse);
+    rpc RenderInvoice(RenderInvoiceRequest) returns (stream RenderInvoiceResponse);
+    rpc SealInvoice(SealInvoiceRequest) returns (SealInvoiceResponse);
+}
diff --git a/bgpwtf/invoice/render.go b/bgpwtf/invoice/render.go
index 2353014..693aa62 100644
--- a/bgpwtf/invoice/render.go
+++ b/bgpwtf/invoice/render.go
@@ -8,8 +8,8 @@
 
 	wkhtml "github.com/sebastiaanklippert/go-wkhtmltopdf"
 
+	pb "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto"
 	"code.hackerspace.pl/hscloud/bgpwtf/invoice/templates"
-	pb "code.hackerspace.pl/hscloud/proto/invoice"
 )
 
 var (
diff --git a/bgpwtf/invoice/statusz.go b/bgpwtf/invoice/statusz.go
index 0a64ce4..9490660 100644
--- a/bgpwtf/invoice/statusz.go
+++ b/bgpwtf/invoice/statusz.go
@@ -7,9 +7,9 @@
 	"sort"
 	"time"
 
+	pb "code.hackerspace.pl/hscloud/bgpwtf/invoice/proto"
 	"code.hackerspace.pl/hscloud/go/mirko"
 	"code.hackerspace.pl/hscloud/go/statusz"
-	pb "code.hackerspace.pl/hscloud/proto/invoice"
 	"github.com/golang/glog"
 )