syntax = "proto3";

package io.restorecommerce.fulfillment_product;

import "io/restorecommerce/reference.proto";
import "io/restorecommerce/resource_base.proto";
import "io/restorecommerce/meta.proto";
import "io/restorecommerce/auth.proto";
import "io/restorecommerce/status.proto";
import "io/restorecommerce/attribute.proto";
import "io/restorecommerce/address.proto";
import "io/restorecommerce/amount.proto";
import "io/restorecommerce/price.proto";
import "io/restorecommerce/geometry.proto";
import "io/restorecommerce/fulfillment_courier.proto";
import "io/restorecommerce/fulfillment.proto";
import "io/restorecommerce/options.proto";

/**
Microservice defination
*/

service FulfillmentProductService {
  rpc Read (io.restorecommerce.resourcebase.ReadRequest) returns (FulfillmentProductListResponse) {
    option (io.restorecommerce.options.is_query) = true;
  };
  rpc Find (FulfillmentSolutionQueryList) returns (FulfillmentSolutionListResponse) {
    option (io.restorecommerce.options.is_query) = true;
  };
  rpc Create (FulfillmentProductList) returns (FulfillmentProductListResponse);
  rpc Update (FulfillmentProductList) returns (FulfillmentProductListResponse);
  rpc Upsert (FulfillmentProductList) returns (FulfillmentProductListResponse);
  rpc Delete (io.restorecommerce.resourcebase.DeleteRequest) returns (io.restorecommerce.resourcebase.DeleteResponse);
}

message Preferences {
  optional bool partial_fulfillment_allowed = 1;
  repeated string courier_ids = 2; // Narrows search to certain couriers, leave empty for open search
  repeated string fulfillment_product_ids = 3; // Narrows search to certain tariffs, leave empty for open search
  repeated io.restorecommerce.attribute.Attribute options = 4; // Courier specific options such as CO2 neutral delivery etc.
}

message FulfillmentSolutionQuery {
  optional string customer_id = 1 [
    (io.restorecommerce.options.resolver) = {
      target_type: ".io.restorecommerce.customer.Customer",
      target_service: "master_data",
      target_sub_service: "customer",
      target_method: "Read",
      field_name: "customer",
    }
  ];
  optional string shop_id = 2 [
    (io.restorecommerce.options.resolver) = {
      target_type: ".io.restorecommerce.shop.Shop",
      target_service: "master_data",
      target_sub_service: "shop",
      target_method: "Read",
      field_name: "shop",
    }
  ];
  optional io.restorecommerce.address.ShippingAddress sender = 3;
  optional io.restorecommerce.address.ShippingAddress recipient = 4;
  repeated io.restorecommerce.fulfillment.Item items = 5;
  optional Preferences preferences = 6;
  optional io.restorecommerce.reference.Reference reference = 7;
}

message FulfillmentSolutionQueryList {
  repeated FulfillmentSolutionQuery items = 1;
  optional uint32 total_count = 2;
  optional io.restorecommerce.auth.Subject subject = 3;
}

message FulfillmentProduct {
  option (restorecommerce.options.kafka_subscriber) = {
    plural: "fulfillment_products"
    topic: "io.restorecommerce.fulfillment_product.resource"
    created: "fulfillmentProductCreated"
    updated: "fulfillmentProductUpdated"
    deleted: "fulfillmentProductDeleted"
  };

  optional string id = 1;
  optional string name = 2;
  optional string description = 3;
  optional string courier_id = 4 [
    (io.restorecommerce.options.resolver) = {
      target_type: ".io.restorecommerce.fulfillment_courier.FulfillmentCourier",
      target_service: "fulfillment",
      target_sub_service: "fulfillment_courier",
      target_method: "Read",
      field_name: "courier",
    }
  ];
  repeated string start_zones = 6;
  repeated string destination_zones = 7;
  repeated string tax_ids = 8;
  repeated io.restorecommerce.attribute.Attribute attributes = 9;
  repeated Variant variants = 10;
  optional io.restorecommerce.meta.Meta meta = 11;
}

message Variant {
  optional string id = 1;
  optional string name = 2;
  optional string description = 3;
  optional io.restorecommerce.price.Price price = 4;
  optional io.restorecommerce.geometry.BoundingBox3D max_size = 6;
  optional double max_weight = 7;
  repeated io.restorecommerce.attribute.Attribute attributes = 8;
}

message FulfillmentProductList {
  repeated FulfillmentProduct items = 1;
  optional uint32 total_count = 2;
  optional io.restorecommerce.auth.Subject subject = 3;
}

message FulfillmentProductResponse {
  optional FulfillmentProduct payload = 1;
  optional io.restorecommerce.status.Status status = 2;
}

message FulfillmentProductListResponse {
  repeated FulfillmentProductResponse items = 1;
  optional uint32 total_count = 2;
  optional io.restorecommerce.status.OperationStatus operation_status = 3;
}

message FulfillmentSolution {
  repeated string courier_ids = 1;
  repeated io.restorecommerce.fulfillment.Parcel parcels = 2;
  repeated io.restorecommerce.amount.Amount amounts = 3;
}

message FulfillmentSolutionResponse {
  optional io.restorecommerce.reference.Reference reference = 1;
  repeated FulfillmentSolution solutions = 2;
  optional io.restorecommerce.status.Status status = 3;
}

message FulfillmentSolutionListResponse {
  repeated FulfillmentSolutionResponse items = 1;
  optional uint32 total_count = 2;
  optional io.restorecommerce.status.OperationStatus operation_status = 3;
}
