| | | 1 | | using MechanicsSoftware.Domain.Enums; |
| | | 2 | | using MechanicsSoftware.Domain.Exceptions; |
| | | 3 | | using MechanicsSoftware.Domain.ValueObjects; |
| | | 4 | | |
| | | 5 | | namespace MechanicsSoftware.Domain.Entities; |
| | | 6 | | |
| | | 7 | | public sealed class PartItem : Entity<Guid> |
| | | 8 | | { |
| | | 9 | | public Guid ServiceOrderId { get; private set; } |
| | | 10 | | public Guid PartId { get; private set; } |
| | | 11 | | public string PartName { get; private set; } = null!; |
| | | 12 | | public Money UnitPrice { get; private set; } = null!; |
| | | 13 | | public int Quantity { get; private set; } |
| | | 14 | | public PartAvailability Availability { get; private set; } |
| | | 15 | | |
| | 16 | 16 | | public Money Total => Availability == PartAvailability.Available |
| | 16 | 17 | | ? UnitPrice.Multiply(Quantity) |
| | 16 | 18 | | : new Money(0); |
| | | 19 | | |
| | 66 | 20 | | private PartItem() { } |
| | | 21 | | |
| | | 22 | | internal static PartItem Create( |
| | | 23 | | Guid serviceOrderId, |
| | | 24 | | Guid partId, |
| | | 25 | | string partName, |
| | | 26 | | Money unitPrice, |
| | | 27 | | int quantity, |
| | | 28 | | PartAvailability availability) |
| | 32 | 29 | | { |
| | 32 | 30 | | if (partId == Guid.Empty) |
| | 2 | 31 | | throw new DomainException("PartId is required."); |
| | | 32 | | |
| | 30 | 33 | | if (string.IsNullOrWhiteSpace(partName)) |
| | 4 | 34 | | throw new DomainException("Part name is required."); |
| | | 35 | | |
| | 26 | 36 | | if (unitPrice is null) |
| | 2 | 37 | | throw new DomainException("Unit price is required."); |
| | | 38 | | |
| | 24 | 39 | | if (quantity <= 0) |
| | 2 | 40 | | throw new DomainException("Quantity must be greater than zero."); |
| | | 41 | | |
| | 22 | 42 | | return new PartItem |
| | 22 | 43 | | { |
| | 22 | 44 | | Id = Guid.NewGuid(), |
| | 22 | 45 | | ServiceOrderId = serviceOrderId, |
| | 22 | 46 | | PartId = partId, |
| | 22 | 47 | | PartName = partName.Trim(), |
| | 22 | 48 | | UnitPrice = unitPrice, |
| | 22 | 49 | | Quantity = quantity, |
| | 22 | 50 | | Availability = availability |
| | 22 | 51 | | }; |
| | 22 | 52 | | } |
| | | 53 | | } |