using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using RomashkiContracts.Extensions; using RomashkiContracts.Infrastructure; using static System.Runtime.InteropServices.JavaScript.JSType; using System.Xml; using RomashkiContracts.Exceptions; namespace RomashkiContracts.DataModels; public class BuyerDataModel(string id, string fio, string email, float totalSpend, double discountSize) : IValidation { public string Id { get; private set; } = id; public string FIO { get; private set; } = fio; public string Email { get; private set; } = email; public float TotalSpend { get; private set; } = totalSpend; public double DiscountSize { get; private set; } = discountSize; public void Validate() { if (Id.IsEmpty()) throw new ValidationException("Field Id is empty"); if (!Id.IsGuid()) throw new ValidationException("The value in the field Id is not a unique identifier"); if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty"); if (Email.IsEmpty()) throw new ValidationException("Field PhoneNumber is empty"); if (TotalSpend < 0) throw new ValidationException("Field TotalSpend cannot be less than 0"); if (!Regex.IsMatch(Email, @"([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)")) throw new ValidationException("Field Email is not an email"); } }