| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationConnectionOverlayOperation.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | namespace Trailblazer.Pathing; |
| | | 9 | | |
| | | 10 | | /// <summary>Identifies the final-state action for a source-owned connection.</summary> |
| | | 11 | | public enum NavigationConnectionOverlayOperationKind |
| | | 12 | | { |
| | | 13 | | /// <summary>Write or replace a complete connection definition.</summary> |
| | | 14 | | Upsert = 0, |
| | | 15 | | |
| | | 16 | | /// <summary>Tombstone the effective source-owned connection.</summary> |
| | | 17 | | Suppress = 1, |
| | | 18 | | |
| | | 19 | | /// <summary>Remove the override or tombstone and restore the baked definition.</summary> |
| | | 20 | | RevertToBake = 2 |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary>Describes one immutable source-owned connection overlay operation.</summary> |
| | | 24 | | public readonly struct NavigationConnectionOverlayOperation |
| | | 25 | | { |
| | | 26 | | private NavigationConnectionOverlayOperation( |
| | | 27 | | string id, |
| | | 28 | | NavigationConnectionOverlayOperationKind kind, |
| | | 29 | | NavigationConnection? connection) |
| | | 30 | | { |
| | 4167 | 31 | | SwiftThrowHelper.ThrowIfNull(id, nameof(id)); |
| | 4167 | 32 | | SwiftThrowHelper.ThrowIfArgument( |
| | 4167 | 33 | | string.IsNullOrWhiteSpace(id), |
| | 4167 | 34 | | nameof(id), |
| | 4167 | 35 | | "Connection id cannot be empty or whitespace."); |
| | | 36 | | |
| | 4167 | 37 | | Id = id; |
| | 4167 | 38 | | Kind = kind; |
| | 4167 | 39 | | Connection = connection; |
| | 4167 | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <summary>Gets the stable source-map-local connection identifier.</summary> |
| | | 43 | | public string Id { get; } |
| | | 44 | | |
| | | 45 | | /// <summary>Gets the final-state operation kind.</summary> |
| | | 46 | | public NavigationConnectionOverlayOperationKind Kind { get; } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Gets the complete definition for <see cref="NavigationConnectionOverlayOperationKind.Upsert"/>. |
| | | 50 | | /// The value is ignored for suppression and reversion. |
| | | 51 | | /// </summary> |
| | | 52 | | public NavigationConnection? Connection { get; } |
| | | 53 | | |
| | | 54 | | /// <summary>Creates an Upsert operation from a complete connection definition.</summary> |
| | | 55 | | public static NavigationConnectionOverlayOperation Upsert(NavigationConnection connection) |
| | | 56 | | { |
| | 4148 | 57 | | SwiftThrowHelper.ThrowIfNull(connection, nameof(connection)); |
| | 4147 | 58 | | return new(connection.Id, NavigationConnectionOverlayOperationKind.Upsert, connection); |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <summary>Creates a source-owned connection tombstone.</summary> |
| | | 62 | | public static NavigationConnectionOverlayOperation Suppress(string id) => |
| | 16 | 63 | | new(id, NavigationConnectionOverlayOperationKind.Suppress, default); |
| | | 64 | | |
| | | 65 | | /// <summary>Creates an operation that restores the baked source-owned connection.</summary> |
| | | 66 | | public static NavigationConnectionOverlayOperation RevertToBake(string id) => |
| | 4 | 67 | | new(id, NavigationConnectionOverlayOperationKind.RevertToBake, default); |
| | | 68 | | |
| | | 69 | | } |