using SmallSoftwareContracts.Enums; using SmallSoftwareContracts.Exceptions; using SmallSoftwareContracts.Extensions; using SmallSoftwareContracts.Infrastructure; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace SmallSoftwareContracts.DataModels; public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string manufacturerId, double price, bool isDeleted) : IValidation { private readonly ManufacturerDataModel? _manufacturer; public string Id { get; private set; } = id; public string SoftwareName { get; private set; } = softwareName; public SoftwareType SoftwareType { get; private set; } = softwareType; public string ManufacturerId { get; private set; } = manufacturerId; public double Price { get; private set; } = price; public bool IsDeleted { get; private set; } = isDeleted; public string ManufacturerName => _manufacturer?.ManufacturerName ?? string.Empty; public SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string manufacturerId, double price, bool isDeleted, ManufacturerDataModel manufacturer) : this(id, softwareName, softwareType, manufacturerId, price, isDeleted) { _manufacturer = manufacturer; } public SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string manufacturerId, double price) : this(id, softwareName, softwareType, manufacturerId, price, false) { } 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 (SoftwareName.IsEmpty()) throw new ValidationException("Field SoftwareName is empty"); if (SoftwareType == SoftwareType.None) throw new ValidationException("Field SoftwareType 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"); } }