diff --git a/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs b/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs
index 47cfa7c73..f3c04f595 100644
--- a/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs
+++ b/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs
@@ -1,4 +1,5 @@
-using System;
+using Catalog.API.Infrastructure.Exceptions;
+using System;
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
{
@@ -14,8 +15,6 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
public string PictureUri { get; set; }
- public int Stock { get; set; }
-
public int CatalogTypeId { get; set; }
public CatalogType CatalogType { get; set; }
@@ -24,6 +23,79 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
public CatalogBrand CatalogBrand { get; set; }
- public CatalogItem() { }
+ // Quantity in stock
+ public int AvailableStock { get; set; }
+
+ // Available stock at which we should reorder
+ public int RestockThreshold { get; set; }
+
+
+ // Maximum number of units that can be in-stock at any time (due to physicial/logistical constraints in warehouses)
+ public int MaxStockThreshold { get; set; }
+
+ ///
+ /// True if item is on reorder
+ ///
+ public bool OnReorder { get; set; }
+
+ public CatalogItem() { }
+
+
+ ///
+ /// Decrements the quantity of a particular item in inventory and ensures the restockThreshold hasn't
+ /// been breached. If so, a RestockRequest is generated in CheckThreshold.
+ ///
+ /// If there is sufficient stock of an item, then the integer returned at the end of this call should be the same as quantityDesired.
+ /// In the event that there is not sufficient stock available, the method will remove whatever stock is available and return that quantity to the client.
+ /// In this case, it is the responsibility of the client to determine if the amount that is returned is the same as quantityDesired.
+ /// It is invalid to pass in a negative number.
+ ///
+ ///
+ /// int: Returns the number actually removed from stock.
+ ///
+ public int RemoveStock(int quantityDesired)
+ {
+ if (AvailableStock == 0)
+ {
+ throw new CatalogDomainException($"Empty stock, product item {Name} is sold out");
+ }
+
+ if (quantityDesired <= 0)
+ {
+ throw new CatalogDomainException($"Item units desired should be greater than cero");
+ }
+
+ int removed = Math.Min(quantityDesired, this.AvailableStock);
+
+ this.AvailableStock -= removed;
+
+ return removed;
+ }
+
+ ///
+ /// Increments the quantity of a particular item in inventory.
+ ///
+ /// int: Returns the quantity that has been added to stock
+ ///
+ public int AddStock(int quantity)
+ {
+ int original = this.AvailableStock;
+
+ // The quantity that the client is trying to add to stock is greater than what can be physically accommodated in the Warehouse
+ if ((this.AvailableStock + quantity) > this.MaxStockThreshold)
+ {
+ // For now, this method only adds new units up maximum stock threshold. In an expanded version of this application, we
+ //could include tracking for the remaining units and store information about overstock elsewhere.
+ this.AvailableStock += (this.MaxStockThreshold - this.AvailableStock);
+ }
+ else
+ {
+ this.AvailableStock += quantity;
+ }
+
+ this.OnReorder = false;
+
+ return this.AvailableStock - original;
+ }
}
-}
+}
\ No newline at end of file