| | | 1 | | using MechanicsSoftware.Domain.Exceptions; |
| | | 2 | | using MechanicsSoftware.Domain.ValueObjects; |
| | | 3 | | |
| | | 4 | | namespace MechanicsSoftware.Domain.Entities; |
| | | 5 | | |
| | | 6 | | public sealed class Service : Entity<Guid> |
| | | 7 | | { |
| | | 8 | | public string Name { get; private set; } = null!; |
| | | 9 | | public string? Description { get; private set; } |
| | | 10 | | public Money BasePrice { get; private set; } = null!; |
| | | 11 | | public int EstimatedMinutes { get; private set; } |
| | | 12 | | |
| | 132 | 13 | | private Service() { } |
| | | 14 | | |
| | | 15 | | public static Service Create( |
| | | 16 | | Guid id, |
| | | 17 | | string name, |
| | | 18 | | string? description, |
| | | 19 | | Money basePrice, |
| | | 20 | | int estimatedMinutes = 0) |
| | 60 | 21 | | { |
| | 60 | 22 | | if (id == Guid.Empty) |
| | 2 | 23 | | throw new DomainException("Id is required."); |
| | | 24 | | |
| | 58 | 25 | | if (string.IsNullOrWhiteSpace(name)) |
| | 6 | 26 | | throw new DomainException("Name is required."); |
| | | 27 | | |
| | 52 | 28 | | if (basePrice is null) |
| | 2 | 29 | | throw new DomainException("Base price is required."); |
| | | 30 | | |
| | 50 | 31 | | if (estimatedMinutes <= 0) |
| | 6 | 32 | | throw new DomainException("EstimatedMinutes must be positive."); |
| | | 33 | | |
| | 44 | 34 | | return new Service |
| | 44 | 35 | | { |
| | 44 | 36 | | Id = id, |
| | 44 | 37 | | Name = name.Trim(), |
| | 44 | 38 | | Description = description?.Trim(), |
| | 44 | 39 | | BasePrice = basePrice, |
| | 44 | 40 | | EstimatedMinutes = estimatedMinutes |
| | 44 | 41 | | }; |
| | 44 | 42 | | } |
| | | 43 | | |
| | | 44 | | public void Update(string name, string? description, Money basePrice, int estimatedMinutes) |
| | 2 | 45 | | { |
| | 2 | 46 | | if (string.IsNullOrWhiteSpace(name)) |
| | 0 | 47 | | throw new DomainException("Name is required."); |
| | | 48 | | |
| | 2 | 49 | | if (basePrice is null) |
| | 0 | 50 | | throw new DomainException("Base price is required."); |
| | | 51 | | |
| | 2 | 52 | | if (estimatedMinutes <= 0) |
| | 0 | 53 | | throw new DomainException("EstimatedMinutes must be positive."); |
| | | 54 | | |
| | 2 | 55 | | Name = name.Trim(); |
| | 2 | 56 | | Description = description?.Trim(); |
| | 2 | 57 | | BasePrice = basePrice; |
| | 2 | 58 | | EstimatedMinutes = estimatedMinutes; |
| | 2 | 59 | | } |
| | | 60 | | } |