using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChudoObuv.Logic
{
///
/// Алгоритмы расчета показателей товара.
///
public static class PriceCalculator
{
public const decimal DiscountPercent = 25m;
public const int ManyQuantityThreshold = 5;
public const int LowStockThreshold = 3;
///
/// Начало предыдущего календарного месяца относительно даты расчета.
///
public static DateTime GetPreviousMonthStart(DateTime calculationDate)
{
return GetCurrentMonthStart(calculationDate).AddMonths(-1);
}
public static DateTime GetCurrentMonthStart(DateTime calculationDate)
{
return new DateTime(calculationDate.Year, calculationDate.Month, 1);
}
///
/// Цена со скидкой 25%, если в предыдущем календарном месяце заказов товара не было.
///
public static decimal CalculateDiscountedPrice(decimal price, bool hasOrdersInPreviousMonth)
{
if (hasOrdersInPreviousMonth)
{
return price;
}
return Math.Round(price * (100m - DiscountPercent) / 100m, 2);
}
///
/// «много», если пар больше пяти, иначе «мало».
///
public static string GetQuantityLabel(int totalQuantity)
{
return totalQuantity > ManyQuantityThreshold ? "много" : "мало";
}
public static bool IsLowStock(int totalQuantity)
{
return totalQuantity <= LowStockThreshold;
}
}
}