| | | 1 | | using MechanicsSoftware.Domain.Exceptions; |
| | | 2 | | using MechanicsSoftware.Domain.ValueObjects; |
| | | 3 | | |
| | | 4 | | namespace MechanicsSoftware.Domain.Entities; |
| | | 5 | | |
| | | 6 | | public sealed class Budget : Entity<Guid> |
| | | 7 | | { |
| | | 8 | | public Guid ServiceOrderId { get; private set; } |
| | | 9 | | public Money Total { get; private set; } = null!; |
| | | 10 | | public BudgetStatus Status { get; private set; } = null!; |
| | | 11 | | public DateTime CreatedAt { get; private set; } |
| | | 12 | | |
| | 330 | 13 | | private Budget() { } |
| | | 14 | | |
| | | 15 | | internal static Budget Create(Guid serviceOrderId, Money total) |
| | 94 | 16 | | { |
| | 94 | 17 | | if (total is null) |
| | 0 | 18 | | throw new DomainException("Budget total is required."); |
| | | 19 | | |
| | 94 | 20 | | return new Budget |
| | 94 | 21 | | { |
| | 94 | 22 | | Id = Guid.NewGuid(), |
| | 94 | 23 | | ServiceOrderId = serviceOrderId, |
| | 94 | 24 | | Total = total, |
| | 94 | 25 | | Status = BudgetStatus.CreatePending(), |
| | 94 | 26 | | CreatedAt = DateTime.UtcNow |
| | 94 | 27 | | }; |
| | 94 | 28 | | } |
| | | 29 | | |
| | | 30 | | internal void Approve() |
| | 48 | 31 | | { |
| | 48 | 32 | | Status = Status.TransitionTo(BudgetStatus.Status.Approved); |
| | 48 | 33 | | } |
| | | 34 | | |
| | | 35 | | internal void Reject() |
| | 16 | 36 | | { |
| | 16 | 37 | | Status = Status.TransitionTo(BudgetStatus.Status.Rejected); |
| | 16 | 38 | | } |
| | | 39 | | } |