Skip to content

Commit 0fa0c9e

Browse files
committed
fix: Handles subscription status conversion
Handles the conversion of subscription status from a string value to the `SubscriptionStatus` enum. This change ensures proper handling of status values, including cases where the string representation doesn't directly map to an enum value or represents a duplicate subscription.
1 parent 1da19a8 commit 0fa0c9e

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

libs/HyperGuestSDK/Api/Pdm/Subscriptions/Subscription.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Subscription
3232
/// Gets or sets the status.
3333
/// </summary>
3434
[JsonPropertyName("status")]
35-
public SubscriptionStatus Status { get; set; }
35+
public string? StatusValue { get; set; }
3636

3737
/// <summary>
3838
/// Gets or sets the status change comment.
@@ -51,6 +51,29 @@ public class Subscription
5151
/// </summary>
5252
[JsonPropertyName("version")]
5353
public int Version { get; set; }
54+
55+
#region Presentational
56+
/// <summary>
57+
/// Gets the status as a <see cref="SubscriptionStatus"/> enum value.
58+
/// </summary>
59+
public SubscriptionStatus Status
60+
{
61+
get
62+
{
63+
if (Enum.TryParse<SubscriptionStatus>(StatusValue, true, out var status))
64+
{
65+
return status;
66+
}
67+
68+
if (string.Equals("already exists", StatusValue, StringComparison.OrdinalIgnoreCase))
69+
{
70+
return SubscriptionStatus.Duplicate;
71+
}
72+
73+
return SubscriptionStatus.Unknown;
74+
}
75+
}
76+
#endregion
5477
}
5578

5679
/// <summary>
@@ -121,7 +144,17 @@ public enum SubscriptionStatus
121144
/// <summary>
122145
/// The subscription has ended.
123146
/// </summary>
124-
Unsubscribed
147+
Unsubscribed,
148+
149+
/// <summary>
150+
/// The subscription is a duplicate of another subscription.
151+
/// </summary>
152+
Duplicate,
153+
154+
/// <summary>
155+
/// The subscription status is unknown.
156+
/// </summary>
157+
Unknown
125158
}
126159

127160
#region Create Requests

0 commit comments

Comments
 (0)