30 lines
966 B
C#

using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
using TheCyclopsContracts.Infrastructure;
namespace TheCyclopsContracts.DataModels;
public class StorageDataModel(string id, string address, List<StorageComponentDataModel> components) : IValidation
{
public string Id { get; private set; } = id;
public string Address { get; private set; } = address;
public List<StorageComponentDataModel> Components { get; private set; } = components;
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 (Address.IsEmpty())
throw new ValidationException("Field Address is empty");
if ((Components?.Count ?? 0) == 0)
throw new ValidationException("The supply must include components");
}
}