Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
KycTransitions.cs
1using System;
3using System.Linq;
4
6{
10 internal static class KycTransitions
11 {
15 public static KycNavigationSnapshot Advance(KycProcessState State, IReadOnlyList<int> VisibleIndices)
16 {
17 KycNavigationSnapshot nav = State.Navigation;
18 if (State.Navigation.State is KycFlowState.Summary or KycFlowState.PendingSummary)
19 return nav; // Already at summary; engine will decide apply action.
20
21 // Find next visible page after current
22 int Current = nav.CurrentPageIndex;
23 int Next = -1;
24 foreach (int idx in VisibleIndices)
25 {
26 if (idx > Current) { Next = idx; break; }
27 }
28 if (Next < 0)
29 {
30 // No further pages -> transition to summary
31 return nav with { State = State.ApplicationSent ? KycFlowState.PendingSummary : KycFlowState.Summary };
32 }
33 return nav with { CurrentPageIndex = Next };
34 }
35
39 public static KycNavigationSnapshot Back(KycProcessState state, IReadOnlyList<int> visibleIndices)
40 {
41 KycNavigationSnapshot Nav = state.Navigation;
42 if (Nav.State == KycFlowState.Summary)
43 {
44 // Leave summary returning to anchor page
45 return Nav with { State = KycFlowState.Form, CurrentPageIndex = Nav.AnchorPageIndex >= 0 ? Nav.AnchorPageIndex : Nav.CurrentPageIndex };
46 }
47 int Current = Nav.CurrentPageIndex;
48 int Prev = -1;
49 for (int i = visibleIndices.Count - 1; i >= 0; i--)
50 {
51 int idx = visibleIndices[i];
52 if (idx < Current) { Prev = idx; break; }
53 }
54 if (Prev < 0)
55 return Nav; // At first page; caller decides to exit.
56 return Nav with { CurrentPageIndex = Prev };
57 }
58
62 public static KycNavigationSnapshot EnterSummary(KycProcessState state)
63 {
64 KycNavigationSnapshot Nav = state.Navigation;
65 if (Nav.State == KycFlowState.Summary) return Nav;
66 return Nav with { State = state.ApplicationSent ? KycFlowState.PendingSummary : KycFlowState.Summary, AnchorPageIndex = Nav.CurrentPageIndex };
67 }
68
72 public static KycNavigationSnapshot EditFromSummary(KycProcessState state, int targetPageIndex)
73 {
74 KycNavigationSnapshot Nav = state.Navigation;
75 if (Nav.State != KycFlowState.Summary && Nav.State != KycFlowState.RejectedSummary)
76 return Nav; // Only allowed from summary flavors
77 return new KycNavigationSnapshot(targetPageIndex, Nav.AnchorPageIndex >= 0 ? Nav.AnchorPageIndex : Nav.CurrentPageIndex, KycFlowState.EditingFromSummary);
78 }
79
83 public static KycNavigationSnapshot ReturnToSummary(KycProcessState state, bool hasInvalid)
84 {
85 KycNavigationSnapshot Nav = state.Navigation;
86 if (Nav.State != KycFlowState.EditingFromSummary) return Nav;
87 if (hasInvalid)
88 return Nav with { State = KycFlowState.Form }; // Caller may reposition to first invalid
89 return Nav with { State = KycFlowState.Summary, CurrentPageIndex = Nav.AnchorPageIndex >= 0 ? Nav.AnchorPageIndex : Nav.CurrentPageIndex };
90 }
91 }
92}
sealed record KycProcessState(IReadOnlyList< KycPageState > Pages, KycNavigationSnapshot Navigation, bool ApplicationSent)
Root aggregate-like snapshot passed through pure functions.
Definition: KycDomain.cs:45
KycFlowState
High-level flow states for the KYC process UI.
Definition: KycDomain.cs:7
sealed record KycNavigationSnapshot(int CurrentPageIndex, int AnchorPageIndex, KycFlowState State)
Navigation snapshot capturing minimal mutable UI navigation state.