mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 04:53:11 +00:00
86 lines
No EOL
3.7 KiB
C#
86 lines
No EOL
3.7 KiB
C#
using Data.SeaHavenIndustries.Enums;
|
|
|
|
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
|
|
{
|
|
|
|
public static class LifecycleStatusMapper
|
|
|
|
{
|
|
|
|
public static LifecycleStatus? FromLegacyStatus(string? status)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(status)) return null;
|
|
|
|
|
|
|
|
return status.Trim().ToLowerInvariant() switch
|
|
|
|
{
|
|
|
|
"open" or "incomplete" => LifecycleStatus.Incomplete,
|
|
|
|
"pending" or "onhold" or "on hold" => LifecycleStatus.Pending,
|
|
|
|
"scheduled" => LifecycleStatus.Scheduled,
|
|
|
|
"en route" or "enroute" => LifecycleStatus.EnRoute,
|
|
|
|
"on site" or "onsite" => LifecycleStatus.OnSite,
|
|
|
|
"inprogress" or "in progress" => LifecycleStatus.InProgress,
|
|
|
|
"completed" or "complete" or "done" or "closed" => LifecycleStatus.Completed,
|
|
|
|
"rescheduled" => LifecycleStatus.Rescheduled,
|
|
|
|
"cancelled" or "canceled" => LifecycleStatus.Canceled,
|
|
|
|
"pending quote" or "pendingquote" or "pendingapproval" or "pending approval" => LifecycleStatus.PendingQuote,
|
|
|
|
_ => LifecycleStatus.Incomplete
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static LifecycleStatus? ParseLifecycleStatus(string? value)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(value)) return null;
|
|
|
|
|
|
|
|
if (TryParseFeLabel(value, out var fromLabel))
|
|
|
|
return fromLabel;
|
|
|
|
|
|
|
|
if (Enum.TryParse<LifecycleStatus>(value, true, out var parsed))
|
|
|
|
return parsed;
|
|
|
|
|
|
|
|
return FromLegacyStatus(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool TryParseFeLabel(string? label, out LifecycleStatus status)
|
|
|
|
{
|
|
|
|
status = default;
|
|
|
|
if (string.IsNullOrWhiteSpace(label)) return false;
|
|
|
|
|
|
|
|
return label.Trim().ToLowerInvariant() switch
|
|
|
|
{
|
|
|
|
"incomplete" => Set(LifecycleStatus.Incomplete, out status),
|
|
|
|
"pending" => Set(LifecycleStatus.Pending, out status),
|
|
|
|
"scheduled" => Set(LifecycleStatus.Scheduled, out status),
|
|
|
|
"en route" => Set(LifecycleStatus.EnRoute, out status),
|
|
|
|
"on site" => Set(LifecycleStatus.OnSite, out status),
|
|
|
|
"in progress" => Set(LifecycleStatus.InProgress, out status),
|
|
|
|
"completed" => Set(LifecycleStatus.Completed, out status),
|
|
|
|
"rescheduled" => Set(LifecycleStatus.Rescheduled, out status),
|
|
|
|
"canceled" => Set(LifecycleStatus.Canceled, out status),
|
|
|
|
"pending quote" => Set(LifecycleStatus.PendingQuote, out status),
|
|
|
|
_ => false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string ToFeLabel(LifecycleStatus status) => status switch
|
|
|
|
{
|
|
|
|
LifecycleStatus.Incomplete => "Incomplete",
|
|
|
|
LifecycleStatus.Pending => "Pending",
|
|
|
|
LifecycleStatus.Scheduled => "Scheduled",
|
|
|
|
LifecycleStatus.EnRoute => "En Route",
|
|
|
|
LifecycleStatus.OnSite => "On Site",
|
|
|
|
LifecycleStatus.InProgress => "In Progress",
|
|
|
|
LifecycleStatus.Completed => "Completed",
|
|
|
|
LifecycleStatus.Rescheduled => "Rescheduled",
|
|
|
|
LifecycleStatus.Canceled => "Canceled",
|
|
|
|
LifecycleStatus.PendingQuote => "Pending Quote",
|
|
|
|
_ => status.ToString()
|
|
|
|
};
|
|
|
|
|
|
|
|
public static bool IsTerminal(LifecycleStatus? status)
|
|
|
|
=> status is LifecycleStatus.Completed or LifecycleStatus.Canceled;
|
|
|
|
|
|
|
|
private static bool Set(LifecycleStatus value, out LifecycleStatus status)
|
|
|
|
{
|
|
|
|
status = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|