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

service Product {
  // Create new product
  rpc CreateProduct(NewProduct) returns (ProductObj);
  // Get all product IDs
  rpc GetProductAll(google.protobuf.Empty) returns (ProductIds);
  // Get product by ID
  rpc GetProduct(GetProductRequest) returns (ProductObj);
  // Get products by IDs
  rpc GetProductBulk(GetProductBulkRequest) returns (stream ProductObj);
  // Update product by ID
  rpc UpdateProduct(ProductObj) returns (ProductObj);
  // Find products by query
  rpc FindProduct(FindProductRequest) returns (SkuIds);
  // Create new SKU
  rpc CreateSku(NewSku) returns (SkuObj);
  // Get all SKU IDs
  rpc GetSkuAll(google.protobuf.Empty) returns (SkuIds);
  // Get SKU by ID
  rpc GetSku(GetSkuRequest) returns (SkuObj);
  // Get SKUs by IDs
  rpc GetSkuBulk(GetSkuBulkRequest) returns (stream SkuObj);
  // Update SKU by ID
  rpc UpdateSku(SkuObj) returns (SkuObj);
  // Update SKU divide
  rpc UpdateSkuDivide(UpdateSkuDivideRequest) returns (SkuObj);
  // Find SKUs by query
  rpc FindSku(FindSkuRequest) returns (SkuIds);
}

message e {}

message ProductObj {
  uint32 product_id = 1;
  string name = 2;
  string description = 3;
  string unit = 4;
  repeated uint32 skus = 5;
  uint32 created_by = 6;
  string created_at = 7;
}

message NewProduct {
  string name = 1;
  string description = 2;
  string unit = 3;
  uint32 created_by = 4;
}

message SkuObj {
  uint32 sku = 1;
  uint32 product_id = 2;
  string subname = 3;
  string display_name = 4;
  string display_packaging = 5;
  string quantity = 6;
  string unit = 7;
  bool can_divide = 8;
  uint32 created_by = 9;
  string created_at = 10;
}

message UpdateSkuDivideRequest {
  uint32 sku = 1;
  bool can_divide = 2;
}

message NewSku {
  uint32 product_id = 1;
  string sub_name = 2;
  string quantity = 3;
  uint32 created_by = 4;
}

message ProductIds { repeated uint32 product_ids = 1; }

message GetProductRequest { uint32 product_id = 1; }

message GetProductBulkRequest { repeated uint32 product_ids = 1; }

message SkuIds { repeated uint32 sku_ids = 1; }

message GetSkuRequest { uint32 sku_id = 1; }

message GetSkuBulkRequest { repeated uint32 sku_id = 1; }

message FindProductRequest { string query = 1; }

message FindSkuRequest { string query = 1; }