using ElectricalRepairServiceContract.Enums; using ElectricalRepairServiceContract.Exceptions; using ElectricalRepairServiceContract.Extensions; using ElectricalRepairServiceContract.Interfaces; using System; using System.Collections.Generic; using System.Diagnostics.Metrics; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace ElectricalRepairServiceContract.DataModels { public class RequestDataModel : IValidation { public string Id { get; private set; } public string Description { get; private set; } public int Cost { get; private set; } public DateTime DateComplete { get; private set; } public RequestType RequestType { get; private set; } public string EmploeeId { get; private set; } public string? ClientId { get; private set; } public List? DetailsUse { get; private set; } public RequestDataModel(string id, RequestType requestType, string? description, int cost, DateTime dateComplete, string emploeeId, string? clientId, List? detailsUses) { Id = id; Description = description; RequestType = requestType; Cost = cost; DateComplete = dateComplete; EmploeeId = emploeeId; ClientId = clientId; DetailsUse = detailsUses; } 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 (EmploeeId.IsEmpty()) throw new ValidationException("Field EmploeeId is empty"); if (!EmploeeId.IsGuid()) throw new ValidationException("The value in the field EmploeeId is not a unique identifier"); if (!ClientId?.IsGuid() ?? false) throw new ValidationException("The value in the field ClientId is not a unique identifier"); if (Description.IsEmpty()) throw new ValidationException("Field Description is empty"); if (DetailsUse?.Count == 0) throw new ValidationException("The request must include detailsUses"); if (Cost < 0) throw new ValidationException("The count must be positive"); } } }