|
| 1 | +class Authenticator { |
| 2 | + final DateTime createdAt; |
| 3 | + final DateTime updatedAt; |
| 4 | + final AuthenticatorType type; |
| 5 | + final AuthenticatorKind kind; |
| 6 | + final String? displayName; |
| 7 | + final String? email; |
| 8 | + final String? phone; |
| 9 | + |
| 10 | + Authenticator.fromJSON(dynamic json) |
| 11 | + : createdAt = DateTime.parse(json["created_at"]), |
| 12 | + updatedAt = DateTime.parse(json["updated_at"]), |
| 13 | + type = AuthenticatorTypeExtension.parse(json["type"]), |
| 14 | + kind = AuthenticatorKindExtension.parse(json["kind"]), |
| 15 | + displayName = json["display_name"], |
| 16 | + email = json["email"], |
| 17 | + phone = json["phone"]; |
| 18 | +} |
| 19 | + |
| 20 | +enum AuthenticatorType { |
| 21 | + password, |
| 22 | + oobOtpEmail, |
| 23 | + oobOtpSms, |
| 24 | + totp, |
| 25 | +} |
| 26 | + |
| 27 | +extension AuthenticatorTypeExtension on AuthenticatorType { |
| 28 | + String get value { |
| 29 | + switch (this) { |
| 30 | + case AuthenticatorType.password: |
| 31 | + return "password"; |
| 32 | + case AuthenticatorType.oobOtpEmail: |
| 33 | + return "oob_otp_email"; |
| 34 | + case AuthenticatorType.oobOtpSms: |
| 35 | + return "oob_otp_sms"; |
| 36 | + case AuthenticatorType.totp: |
| 37 | + return "totp"; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + static AuthenticatorType parse(String value) { |
| 42 | + switch (value) { |
| 43 | + case "password": |
| 44 | + return AuthenticatorType.password; |
| 45 | + case "oob_otp_email": |
| 46 | + return AuthenticatorType.oobOtpEmail; |
| 47 | + case "oob_otp_sms": |
| 48 | + return AuthenticatorType.oobOtpSms; |
| 49 | + case "totp": |
| 50 | + return AuthenticatorType.totp; |
| 51 | + default: |
| 52 | + throw Exception("unknown authenticator type: $value"); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +enum AuthenticatorKind { |
| 58 | + primary, |
| 59 | + secondary, |
| 60 | +} |
| 61 | + |
| 62 | +extension AuthenticatorKindExtension on AuthenticatorKind { |
| 63 | + String get value { |
| 64 | + switch (this) { |
| 65 | + case AuthenticatorKind.primary: |
| 66 | + return "primary"; |
| 67 | + case AuthenticatorKind.secondary: |
| 68 | + return "secondary"; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + static AuthenticatorKind parse(String value) { |
| 73 | + switch (value) { |
| 74 | + case "primary": |
| 75 | + return AuthenticatorKind.primary; |
| 76 | + case "secondary": |
| 77 | + return AuthenticatorKind.secondary; |
| 78 | + default: |
| 79 | + throw Exception("unknown authenticator kind: $value"); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments