| | | 1 | | using MechanicsSoftware.Domain.Exceptions; |
| | | 2 | | |
| | | 3 | | namespace MechanicsSoftware.Domain.ValueObjects; |
| | | 4 | | |
| | 830 | 5 | | public sealed class ServiceOrderStatus(ServiceOrderStatus.Status value) : ValueObject |
| | | 6 | | { |
| | 894 | 7 | | public Status Value => value; |
| | | 8 | | public enum Status |
| | | 9 | | { |
| | | 10 | | Received, |
| | | 11 | | InDiagnosis, |
| | | 12 | | AwaitingApproval, |
| | | 13 | | InExecution, |
| | | 14 | | Completed, |
| | | 15 | | Delivered, |
| | | 16 | | Cancelled |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | protected override IEnumerable<object?> GetEqualityComponents() |
| | 292 | 20 | | { |
| | 292 | 21 | | yield return Value; |
| | 44 | 22 | | } |
| | | 23 | | |
| | 2 | 24 | | private static readonly HashSet<(Status From, Status To)> _validTransitions = |
| | 2 | 25 | | [ |
| | 2 | 26 | | (Status.Received, Status.InDiagnosis), |
| | 2 | 27 | | (Status.InDiagnosis, Status.AwaitingApproval), |
| | 2 | 28 | | (Status.AwaitingApproval, Status.InExecution), |
| | 2 | 29 | | (Status.AwaitingApproval, Status.Cancelled), |
| | 2 | 30 | | (Status.InExecution, Status.Completed), |
| | 2 | 31 | | (Status.Completed, Status.Delivered), |
| | 2 | 32 | | ]; |
| | | 33 | | |
| | | 34 | | public ServiceOrderStatus TransitionTo(Status newStatus) |
| | 386 | 35 | | { |
| | 386 | 36 | | if (!_validTransitions.Contains((value, newStatus))) |
| | 28 | 37 | | throw new InvalidStatusTransitionException(this, new ServiceOrderStatus(newStatus)); |
| | | 38 | | |
| | 358 | 39 | | return new ServiceOrderStatus(newStatus); |
| | 358 | 40 | | } |
| | | 41 | | |
| | 278 | 42 | | public override string ToString() => Value switch |
| | 278 | 43 | | { |
| | 82 | 44 | | Status.Received => "RECEIVED", |
| | 60 | 45 | | Status.InDiagnosis => "IN_DIAGNOSIS", |
| | 36 | 46 | | Status.AwaitingApproval => "AWAITING_APPROVAL", |
| | 40 | 47 | | Status.InExecution => "IN_EXECUTION", |
| | 22 | 48 | | Status.Completed => "COMPLETED", |
| | 18 | 49 | | Status.Delivered => "DELIVERED", |
| | 20 | 50 | | Status.Cancelled => "CANCELLED", |
| | 0 | 51 | | _ => Value.ToString() |
| | 278 | 52 | | }; |
| | | 53 | | |
| | 256 | 54 | | public bool Is(Status s) => Value == s; |
| | | 55 | | |
| | 232 | 56 | | public static ServiceOrderStatus CreateReceived() => new(Status.Received); |
| | | 57 | | } |