45 lines
1.5 KiB
C#

using NorthBridgeContract.Enums;
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.DataModels;
public class ComponentDataModel(string id, string componentName, ComponentType componentType, string manufacturerId, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string ComponentName { get; private set; } = componentName;
public ComponentType ComponentType { get; private set; } = componentType;
public string ManufacturerId { get; private set; } = manufacturerId;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
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 (ComponentName.IsEmpty())
throw new ValidationException("Field ProductName is empty");
if (ComponentType == ComponentType.None)
throw new ValidationException("Field ProductType is empty");
if (ManufacturerId.IsEmpty())
throw new ValidationException("Field ManufacturerId is empty");
if (!ManufacturerId.IsGuid())
throw new ValidationException("The value in the field ManufacturerId is not a unique identifier");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}