| | | 1 | | using AsiBackbone.Core.Acknowledgments; |
| | | 2 | | using AsiBackbone.Core.Results; |
| | | 3 | | |
| | | 4 | | namespace AsiBackbone.AspNetCore.Acknowledgments; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Represents the result of handling a host-submitted acknowledgment challenge response. |
| | | 8 | | /// </summary> |
| | | 9 | | public sealed class AcknowledgmentChallengeResult |
| | | 10 | | { |
| | 23 | 11 | | private AcknowledgmentChallengeResult( |
| | 23 | 12 | | OperationResult result, |
| | 23 | 13 | | AcknowledgmentResponse? acknowledgment) |
| | | 14 | | { |
| | 23 | 15 | | ArgumentNullException.ThrowIfNull(result); |
| | | 16 | | |
| | 23 | 17 | | Result = result; |
| | 23 | 18 | | Acknowledgment = acknowledgment; |
| | 23 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the operation result describing response handling success or failure. |
| | | 23 | | /// </summary> |
| | | 24 | | public OperationResult Result { get; } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the Core acknowledgment response when one was created. |
| | | 28 | | /// </summary> |
| | | 29 | | public AcknowledgmentResponse? Acknowledgment { get; } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets a value indicating whether the response was handled successfully. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <remarks> |
| | | 35 | | /// This reports only that the response was valid and produced an acknowledgment record. It is <see langword="true" |
| | | 36 | | /// when the actor explicitly declined, because a refusal is recorded as a <see cref="AcknowledgmentResponse" /> |
| | | 37 | | /// just like an acceptance. Do not use it to decide whether the operation may continue; use |
| | | 38 | | /// <see cref="CanProceed" /> instead. |
| | | 39 | | /// </remarks> |
| | 28 | 40 | | public bool Succeeded => Result.Succeeded; |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets a value indicating whether the response was accepted by the actor. |
| | | 44 | | /// </summary> |
| | 8 | 45 | | public bool Acknowledged => Acknowledgment?.Acknowledged == true; |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Gets a value indicating whether the response was rejected by the actor. |
| | | 49 | | /// </summary> |
| | 5 | 50 | | public bool Rejected => Acknowledgment?.Rejected == true; |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Gets a value indicating whether the operation that required acknowledgment may continue. |
| | | 54 | | /// </summary> |
| | | 55 | | /// <remarks> |
| | | 56 | | /// This is <see langword="true" /> only when the response was handled successfully and the actor accepted. A handle |
| | | 57 | | /// refusal and every handling failure yield <see langword="false" />. It is the single check a host should gate the |
| | | 58 | | /// consequential operation on, matching <see cref="Core.Decisions.GovernanceDecision.CanProceed" />. |
| | | 59 | | /// </remarks> |
| | 5 | 60 | | public bool CanProceed => Succeeded && Acknowledged; |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Creates a successful acknowledgment challenge result. |
| | | 64 | | /// </summary> |
| | | 65 | | /// <param name="acknowledgment">The Core acknowledgment response.</param> |
| | | 66 | | /// <returns>A successful challenge result.</returns> |
| | | 67 | | public static AcknowledgmentChallengeResult Success(AcknowledgmentResponse acknowledgment) |
| | | 68 | | { |
| | 7 | 69 | | ArgumentNullException.ThrowIfNull(acknowledgment); |
| | | 70 | | |
| | 6 | 71 | | return new AcknowledgmentChallengeResult(OperationResult.Success(), acknowledgment); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Creates a failed acknowledgment challenge result. |
| | | 76 | | /// </summary> |
| | | 77 | | /// <param name="code">The failure reason code.</param> |
| | | 78 | | /// <param name="message">The failure reason message.</param> |
| | | 79 | | /// <returns>A failed challenge result.</returns> |
| | | 80 | | public static AcknowledgmentChallengeResult Failure(string code, string message) |
| | | 81 | | { |
| | 17 | 82 | | return new AcknowledgmentChallengeResult(OperationResult.Failure(code, message), null); |
| | | 83 | | } |
| | | 84 | | } |