| | | 1 | | using AsiBackbone.Core.Handshakes; |
| | | 2 | | using AsiBackbone.Core.Results; |
| | | 3 | | |
| | | 4 | | namespace AsiBackbone.AspNetCore.Handshakes; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Represents the result of handling a host-submitted acknowledgment challenge response. |
| | | 8 | | /// </summary> |
| | | 9 | | public sealed class AsiBackboneAcknowledgmentChallengeResult |
| | | 10 | | { |
| | 26 | 11 | | private AsiBackboneAcknowledgmentChallengeResult( |
| | 26 | 12 | | OperationResult result, |
| | 26 | 13 | | LiabilityHandshakeAcknowledgment? acknowledgment) |
| | | 14 | | { |
| | 26 | 15 | | ArgumentNullException.ThrowIfNull(result); |
| | | 16 | | |
| | 26 | 17 | | Result = result; |
| | 26 | 18 | | Acknowledgment = acknowledgment; |
| | 26 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the operation result describing response handling success or failure. |
| | | 23 | | /// </summary> |
| | 46 | 24 | | public OperationResult Result { get; } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the Core acknowledgment response when one was created. |
| | | 28 | | /// </summary> |
| | 66 | 29 | | public LiabilityHandshakeAcknowledgment? Acknowledgment { get; } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets a value indicating whether the response was handled successfully. |
| | | 33 | | /// </summary> |
| | 26 | 34 | | public bool Succeeded => Result.Succeeded; |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Gets a value indicating whether the response was accepted by the actor. |
| | | 38 | | /// </summary> |
| | 10 | 39 | | public bool Acknowledged => Acknowledgment?.Acknowledged == true; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets a value indicating whether the response was rejected by the actor. |
| | | 43 | | /// </summary> |
| | 10 | 44 | | public bool Rejected => Acknowledgment?.Rejected == true; |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Creates a successful acknowledgment challenge result. |
| | | 48 | | /// </summary> |
| | | 49 | | /// <param name="acknowledgment">The Core acknowledgment response.</param> |
| | | 50 | | /// <returns>A successful challenge result.</returns> |
| | | 51 | | public static AsiBackboneAcknowledgmentChallengeResult Success(LiabilityHandshakeAcknowledgment acknowledgment) |
| | | 52 | | { |
| | 8 | 53 | | ArgumentNullException.ThrowIfNull(acknowledgment); |
| | | 54 | | |
| | 6 | 55 | | return new AsiBackboneAcknowledgmentChallengeResult(OperationResult.Success(), acknowledgment); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Creates a failed acknowledgment challenge result. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="code">The failure reason code.</param> |
| | | 62 | | /// <param name="message">The failure reason message.</param> |
| | | 63 | | /// <returns>A failed challenge result.</returns> |
| | | 64 | | public static AsiBackboneAcknowledgmentChallengeResult Failure(string code, string message) |
| | | 65 | | { |
| | 20 | 66 | | return new AsiBackboneAcknowledgmentChallengeResult(OperationResult.Failure(code, message), null); |
| | | 67 | | } |
| | | 68 | | } |