using AndDietCokeContracts.Extensions; using AndDietCokeContracts.Infrastructure; using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Runtime.InteropServices.JavaScript.JSType; using System.Xml; using AndDietCokeContracts.Exceptions; namespace AndDietCokeContracts.DataModels; public class BuyerDataModel(string id, string fio, string phoneNumber) : IValidation { public string Id { get; private set; } = id; public string FIO { get; private set; } = fio; public string PhoneNumber { get; private set; } = phoneNumber; 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 (PhoneNumber.IsEmpty()) throw new ValidationException("Field PhoneNumber is empty"); if (!Regex.IsMatch(PhoneNumber, @"^(((8|\+7)[\-\s]?)?(\(?\d{3}\)?[\-\s]?)?[\d\-\s]{7,10}|(\d{2}[\-\s]?\d{2}[\-\s]?\d{2}))$")) throw new ValidationException("Field PhoneNumber is not a phone number"); } }