using NorthwindBackend.NorthwindServiceReference;

namespace NorthwindBackend
{
	/// <summary>
	/// Storage for saving and restoring Product properties
	/// </summary>
	public class ProductState
	{
		private Product original;
		private Product saved;

		/// <summary>
		/// Clears the saved product properties.
		/// </summary>
		public void Clear()
		{
			this.saved = null;
		}

		/// <summary>
		/// Saves the properties of the specified product.
		/// </summary>
		/// <param name="product">The product.</param>
		public void Save(Product product)
		{
			if (this.saved != null)
			{
				this.Restore();
			}

			this.original = product;
			this.saved = new Product();
			this.saved.Category = product.Category;
			this.saved.Discontinued = product.Discontinued;
			this.saved.ProductID = product.ProductID;
			this.saved.ProductName = product.ProductName;
			this.saved.QuantityPerUnit = product.QuantityPerUnit;
			this.saved.ReorderLevel = product.ReorderLevel;
			this.saved.Supplier = product.Supplier;
			this.saved.UnitPrice = product.UnitPrice;
			this.saved.UnitsInStock = product.UnitsInStock;
			this.saved.UnitsOnOrder = product.UnitsOnOrder;

		}

		/// <summary>
		/// Restores the saved product properties.
		/// </summary>
		public void Restore()
		{
			if (this.saved != null)
			{
				this.original.Category = this.saved.Category;
				this.original.Discontinued = this.saved.Discontinued;
				this.original.ProductID = this.saved.ProductID;
				this.original.ProductName = this.saved.ProductName;
				this.original.QuantityPerUnit = this.saved.QuantityPerUnit;
				this.original.ReorderLevel = this.saved.ReorderLevel;
				this.original.Supplier = this.saved.Supplier;
				this.original.UnitPrice = this.saved.UnitPrice;
				this.original.UnitsInStock = this.saved.UnitsInStock;
				this.original.UnitsOnOrder = this.saved.UnitsOnOrder;
				this.Clear();
			}
		}
	}
}