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

service Source {
  // Create new source
  rpc CreateSource(CreateSourceRequest) returns (SourceObject);
  // Get source data (no SKUs and prices)
  rpc GetSource(GetSourceRequest) returns (SourceObject);
  // Update source data (just source business data)
  rpc UpdateSource(SourceObject) returns (SourceObject);
  // Get all sources (SourceObject)
  rpc GetAllSources(google.protobuf.Empty) returns (stream SourceObject);
  // Get all sku prices per source
  rpc GetPrices(GetPricesRequest) returns (stream GetPriceInfoResponse);
  // Add price info to a source/sku
  rpc AddPriceInfo(AddPriceInfoRequest) returns (stream PriceObject);
  // Get price info from a source/sku
  rpc GetPriceInfo(GetPriceInfoRequest) returns (stream GetPriceInfoResponse);
  // Get price info history from a source/sku
  rpc GetPriceInfoHistory(GetPriceInfoHistoryRequest)
      returns (stream PriceObject);
}

message CreateSourceRequest {
  string name = 1;
  string address = 2;
  repeated string email = 3;
  repeated string phone = 4;
  uint32 created_by = 5;
}

message SourceIds { repeated uint32 source_ids = 1; }

// Get SourceObject by source_id
message GetSourceRequest { uint32 source_id = 1; }

// Get all sku prices by source
message GetPricesRequest { uint32 source_id = 1; }

// Get PriceInforResponse by sku
message GetPriceInfoRequest { uint32 sku = 1; }

// Get PriceInfoHistoryResponse by sku
message GetPriceInfoHistoryRequest {
  uint32 source = 1;
  uint32 sku = 2;
}

// Add PriceInfo item to a source_id/SKU
message AddPriceInfoRequest {
  uint32 source_id = 1;
  uint32 sku = 2;
  uint32 net_price = 3;
  string comment = 4;
  uint32 created_by = 5;
}

// Represents source data object (business data)
message SourceObject {
  uint32 id = 1;
  string name = 2;
  string address = 3;
  repeated string email = 4;
  repeated string phone = 5;
  string created_at = 6;
  uint32 created_by = 7;
}

// Represents a price object
message PriceObject {
  // Expected net wholesale price
  uint32 net_price = 1;
  // Comment
  string comment = 2;
  // Created at
  string created_at = 3;
  // Created by userid
  uint32 created_by = 4;
}

message GetPriceInfoResponse {
  // Source id
  uint32 source_id = 1;
  // SKU
  uint32 sku = 2;
  // Latest available price
  PriceObject latest_price = 3;
}

message GetPriceInfoHistoryResponse {
  // Source id
  uint32 source_id = 1;
  // SKU
  uint32 sku = 2;
  // Latest available prices
  repeated PriceObject latest_price = 3;
}
