2025-02-01 23:56:40 +04:00
|
|
|
|
using NorthBridgeContract.Exceptions;
|
|
|
|
|
using NorthBridgeContract.Extensions;
|
|
|
|
|
using NorthBridgeContract.Infrastructure;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace NorthBridgeContract.DataModels;
|
|
|
|
|
|
2025-02-02 00:40:47 +04:00
|
|
|
|
public class BuyerDataModel(string id, string fio, string phoneNumber) : IValidation
|
2025-02-01 23:56:40 +04:00
|
|
|
|
{
|
|
|
|
|
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)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
|
|
|
|
throw new ValidationException("Field PhoneNumber is not a phone number");
|
2025-02-02 00:40:47 +04:00
|
|
|
|
|
|
|
|
|
if (!Regex.IsMatch(FIO, @"^[А-ЯЁ][а-яё]+(?:-[А-ЯЁ][а-яё]+)?\s[А-ЯЁ][а-яё]+(?:\s[А-ЯЁ][а-яё]+)?$"))
|
|
|
|
|
throw new ValidationException("Field FIO is not a fio");
|
2025-02-01 23:56:40 +04:00
|
|
|
|
}
|
|
|
|
|
}
|