|
| 1 | +export class CanceledStateContext { |
| 2 | + developerInitiatedCancellation?: DeveloperInitiatedCancellation; |
| 3 | + replacementCancellation?: ReplacementCancellation; |
| 4 | + systemInitiatedCancellation?: SystemInitiatedCancellation; |
| 5 | + userInitiatedCancellation?: UserInitiatedCancellation; |
| 6 | + |
| 7 | + constructor( |
| 8 | + developerInitiatedCancellation?: DeveloperInitiatedCancellation, |
| 9 | + replacementCancellation?: ReplacementCancellation, |
| 10 | + systemInitiatedCancellation?: SystemInitiatedCancellation, |
| 11 | + userInitiatedCancellation?: UserInitiatedCancellation |
| 12 | + ) { |
| 13 | + this.developerInitiatedCancellation = developerInitiatedCancellation; |
| 14 | + this.replacementCancellation = replacementCancellation; |
| 15 | + this.systemInitiatedCancellation = systemInitiatedCancellation; |
| 16 | + this.userInitiatedCancellation = userInitiatedCancellation; |
| 17 | + } |
| 18 | + |
| 19 | + static fromJson(json: any): CanceledStateContext { |
| 20 | + return new CanceledStateContext( |
| 21 | + json.developerInitiatedCancellation != null |
| 22 | + ? DeveloperInitiatedCancellation.fromJson( |
| 23 | + json.developerInitiatedCancellation |
| 24 | + ) |
| 25 | + : undefined, |
| 26 | + json.replacementCancellation != null |
| 27 | + ? ReplacementCancellation.fromJson(json.replacementCancellation) |
| 28 | + : undefined, |
| 29 | + json.systemInitiatedCancellation != null |
| 30 | + ? SystemInitiatedCancellation.fromJson(json.systemInitiatedCancellation) |
| 31 | + : undefined, |
| 32 | + json.userInitiatedCancellation != null |
| 33 | + ? UserInitiatedCancellation.fromJson(json.userInitiatedCancellation) |
| 34 | + : undefined |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + toJson(): Record<string, any> { |
| 39 | + return { |
| 40 | + developerInitiatedCancellation: |
| 41 | + this.developerInitiatedCancellation?.toJson(), |
| 42 | + replacementCancellation: this.replacementCancellation?.toJson(), |
| 43 | + systemInitiatedCancellation: this.systemInitiatedCancellation?.toJson(), |
| 44 | + userInitiatedCancellation: this.userInitiatedCancellation?.toJson(), |
| 45 | + }; |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * TODO: Need to check each state context further... |
| 51 | + */ |
| 52 | +class DeveloperInitiatedCancellation { |
| 53 | + constructor() {} |
| 54 | + |
| 55 | + static fromJson(json: any): DeveloperInitiatedCancellation { |
| 56 | + // Here you would implement the conversion from JSON to DeveloperInitiatedCancellation instance |
| 57 | + return new DeveloperInitiatedCancellation(); |
| 58 | + } |
| 59 | + |
| 60 | + toJson(): Record<string, unknown> { |
| 61 | + // Here you would implement the conversion from DeveloperInitiatedCancellation instance to JSON |
| 62 | + return {}; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +class ReplacementCancellation { |
| 67 | + constructor() {} |
| 68 | + |
| 69 | + static fromJson(json: any): ReplacementCancellation { |
| 70 | + // Here you would implement the conversion from JSON to ReplacementCancellation instance |
| 71 | + return new ReplacementCancellation(); |
| 72 | + } |
| 73 | + |
| 74 | + toJson(): Record<string, unknown> { |
| 75 | + return {}; |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +class SystemInitiatedCancellation { |
| 80 | + constructor() {} |
| 81 | + |
| 82 | + static fromJson(json: any): SystemInitiatedCancellation { |
| 83 | + // Here you would implement the conversion from JSON to SystemInitiatedCancellation instance |
| 84 | + return new SystemInitiatedCancellation(); |
| 85 | + } |
| 86 | + |
| 87 | + toJson(): Record<string, unknown> { |
| 88 | + // Here you would implement the conversion from SystemInitiatedCancellation instance to JSON |
| 89 | + return {}; |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +class UserInitiatedCancellation { |
| 94 | + cancelSurveyResult?: CancelSurveyResult; // Made optional as per Dart's CancelSurveyResult? declaration |
| 95 | + cancelTime: string; |
| 96 | + |
| 97 | + constructor( |
| 98 | + cancelSurveyResult: CancelSurveyResult | undefined, |
| 99 | + cancelTime: string |
| 100 | + ) { |
| 101 | + this.cancelSurveyResult = cancelSurveyResult; |
| 102 | + this.cancelTime = cancelTime; |
| 103 | + } |
| 104 | + |
| 105 | + static fromJson(json: any): UserInitiatedCancellation { |
| 106 | + return new UserInitiatedCancellation( |
| 107 | + json.cancelSurveyResult != null |
| 108 | + ? CancelSurveyResult.fromJson(json.cancelSurveyResult) |
| 109 | + : undefined, |
| 110 | + json.cancelTime |
| 111 | + ); |
| 112 | + } |
| 113 | + |
| 114 | + toJson(): Record<string, unknown> { |
| 115 | + return { |
| 116 | + cancelSurveyResult: this.cancelSurveyResult?.toJson(), |
| 117 | + cancelTime: this.cancelTime, |
| 118 | + }; |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +class CancelSurveyResult { |
| 123 | + reason: string; |
| 124 | + reasonUserInput: string; |
| 125 | + |
| 126 | + constructor(reason: string, reasonUserInput: string) { |
| 127 | + this.reason = reason; |
| 128 | + this.reasonUserInput = reasonUserInput; |
| 129 | + } |
| 130 | + |
| 131 | + static fromJson(json: any): CancelSurveyResult { |
| 132 | + return new CancelSurveyResult(json.reason, json.reasonUserInput); |
| 133 | + } |
| 134 | + |
| 135 | + toJson(): Record<string, string> { |
| 136 | + return { |
| 137 | + reason: this.reason, |
| 138 | + reasonUserInput: this.reasonUserInput, |
| 139 | + }; |
| 140 | + } |
| 141 | +} |
0 commit comments