| | | 1 | | using MechanicsSoftware.Domain.Exceptions; |
| | | 2 | | using MechanicsSoftware.Domain.ValueObjects; |
| | | 3 | | |
| | | 4 | | namespace MechanicsSoftware.Domain.Entities; |
| | | 5 | | |
| | | 6 | | public sealed class ServiceItem : Entity<Guid> |
| | | 7 | | { |
| | | 8 | | public Guid ServiceOrderId { get; private set; } |
| | | 9 | | public Guid ServiceId { get; private set; } |
| | | 10 | | public string ServiceName { get; private set; } = null!; |
| | | 11 | | public Money UnitPrice { get; private set; } = null!; |
| | | 12 | | public int Quantity { get; private set; } |
| | 124 | 13 | | public Money Total => UnitPrice.Multiply(Quantity); |
| | | 14 | | |
| | 348 | 15 | | private ServiceItem() { } |
| | | 16 | | |
| | | 17 | | internal static ServiceItem Create( |
| | | 18 | | Guid serviceOrderId, |
| | | 19 | | Guid serviceId, |
| | | 20 | | string serviceName, |
| | | 21 | | Money unitPrice, |
| | | 22 | | int quantity) |
| | 110 | 23 | | { |
| | 110 | 24 | | if (serviceId == Guid.Empty) |
| | 2 | 25 | | throw new DomainException("ServiceId is required."); |
| | | 26 | | |
| | 108 | 27 | | if (string.IsNullOrWhiteSpace(serviceName)) |
| | 4 | 28 | | throw new DomainException("Service name is required."); |
| | | 29 | | |
| | 104 | 30 | | if (unitPrice is null) |
| | 2 | 31 | | throw new DomainException("Unit price is required."); |
| | | 32 | | |
| | 102 | 33 | | if (quantity <= 0) |
| | 2 | 34 | | throw new DomainException("Quantity must be greater than zero."); |
| | | 35 | | |
| | 100 | 36 | | return new ServiceItem |
| | 100 | 37 | | { |
| | 100 | 38 | | Id = Guid.NewGuid(), |
| | 100 | 39 | | ServiceOrderId = serviceOrderId, |
| | 100 | 40 | | ServiceId = serviceId, |
| | 100 | 41 | | ServiceName = serviceName.Trim(), |
| | 100 | 42 | | UnitPrice = unitPrice, |
| | 100 | 43 | | Quantity = quantity |
| | 100 | 44 | | }; |
| | 100 | 45 | | } |
| | | 46 | | } |