using Ardalis.SmartEnum; namespace UserProfile.Api.Domain.AggregateModel.ProfileOfUserAggregate; public class LeaveStatus : SmartEnum { /// /// leave is pending and awaiting approval /// public static readonly LeaveStatus Pending = new LeavePendingStatus(); /// /// ongoing /// public static readonly LeaveStatus Ongoing = new LeaveOngoingStatus();// new("Ongoing", 2); /// /// leave is approved and can be taken /// public static readonly LeaveStatus Approved = new LeaveApprovedStatus(); /// /// Leave is completed /// public static readonly LeaveStatus Completed = new LeaveCompletedStatus();// ("Completed", 4); /// /// Leave is rejected and cannot be taken /// public static readonly LeaveStatus Rejected = new LeaveRejectedStatus();// ("Rejected", 5); /// /// The leave was revoked after approval but before commencement. /// public static readonly LeaveStatus Revoked = new LeaveRevokedStatus();// new("Revoked", 6); /// /// The leave was interrupted and the user was called back. /// public static readonly LeaveStatus CalledBack = new LeaveCalledBackStatus();// new("Called Back", 7); /// /// The leave was withdrawn by the user after approval but before commencement. /// public static readonly LeaveStatus Withdrawn = new LeaveWithdrawnStatus();// new("Withdrawn", 8); /// /// The leave was once ongoing but now suspended /// public static readonly LeaveStatus Suspended = new LeaveSuspendedStatus();// new("Suspended", 9); /// /// The leave request was escalated for further review. /// public static readonly LeaveStatus Escalated = new LeaveEscalatedStatus();// new("Suspended", 10); /// /// The leave request was granted and is ready to commence. /// public static readonly LeaveStatus Granted = new LeaveGrantedStatus();// new("Granted", 11); private LeaveStatus(string name, int value) : base(name, value) { } public override string ToString() => Name; private sealed class LeavePendingStatus : LeaveStatus { public LeavePendingStatus() : base("Pending", 1) { } } private sealed class LeaveOngoingStatus : LeaveStatus { public LeaveOngoingStatus() : base("Ongoing", 2) { } } private sealed class LeaveApprovedStatus : LeaveStatus { public LeaveApprovedStatus() : base("Approved", 3) { } } private sealed class LeaveCompletedStatus : LeaveStatus { public LeaveCompletedStatus() : base("Completed", 4) { } } private sealed class LeaveRejectedStatus : LeaveStatus { public LeaveRejectedStatus() : base("Rejected", 5) { } } private sealed class LeaveRevokedStatus : LeaveStatus { public LeaveRevokedStatus() : base("Revoked", 6) { } } private sealed class LeaveCalledBackStatus : LeaveStatus { public LeaveCalledBackStatus() : base("Called Back", 7) { } } private sealed class LeaveWithdrawnStatus : LeaveStatus { public LeaveWithdrawnStatus() : base("Withdrawn", 8) { } } private sealed class LeaveSuspendedStatus : LeaveStatus { public LeaveSuspendedStatus() : base("Suspended", 9) { } } private sealed class LeaveEscalatedStatus : LeaveStatus { public LeaveEscalatedStatus() : base("Escalated", 10) { } } private sealed class LeaveGrantedStatus : LeaveStatus { public LeaveGrantedStatus() : base("Granted", 11) { } } } public static class LeaveStatusExtension { public static bool CanTransitionTo(this LeaveStatus current, LeaveStatus next) { if (current == LeaveStatus.Pending) return next == LeaveStatus.Approved || next == LeaveStatus.Rejected; if (current == LeaveStatus.Approved) return next == LeaveStatus.Granted || next == LeaveStatus.Revoked; if (current == LeaveStatus.Granted) return next == LeaveStatus.Ongoing || next == LeaveStatus.Withdrawn || next == LeaveStatus.Revoked; if (current == LeaveStatus.Ongoing) return next == LeaveStatus.Completed || next == LeaveStatus.CalledBack || next == LeaveStatus.Suspended; if (current == LeaveStatus.Suspended) return next == LeaveStatus.Ongoing || next == LeaveStatus.CalledBack || next == LeaveStatus.Completed; if (current == LeaveStatus.Rejected) return false; if (current == LeaveStatus.Completed) return false; if (current == LeaveStatus.Withdrawn) return false; if (current == LeaveStatus.Revoked) return false; if (current == LeaveStatus.CalledBack) return false; return false; } }