2025-02-26 17:00:16 +04:00

48 lines
1.6 KiB
C#

using SnowMaidenContracts.Enums;
using SnowMaidenContracts.Exceptions;
using SnowMaidenContracts.Extensions;
using SnowMaidenContracts.Infrastructure;
namespace SnowMaidenContracts.DataModels;
// 2. Продажа, помимо работника, содержит клиента/покупателя (Buyer -> Sale) и СПИСОК ПРОДУКТОВ (3. SaleProduct -> Sale)
public class SaleDataModel(string id, string workerId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleProductDataModel> products) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
public double Sum { get; private set; } = sum;
public DiscountType DiscountType { get; private set; } = discountType;
public double Discount { get; private set; } = discount;
public bool IsCancel { get; private set; } = isCancel;
public List<SaleProductDataModel> Products { get; private set; } = products;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field ID is empty");
if (!Id.IsGuid())
throw new ValidationException("The ID is not a unique identifier");
if (WorkerId.IsEmpty())
throw new ValidationException("Field Worker ID is empty");
if (!WorkerId.IsGuid())
throw new ValidationException("The Worker ID is NOT a unique identifier");
if (Sum <= 0)
throw new ValidationException("Field Sum is less than or equal to 0");
if ((Products?.Count ?? 0) == 0)
throw new ValidationException("The sale must include products");
}
}