| 1 | import maps |
| 2 | import x.json2 |
| 3 | |
| 4 | pub type Locale = string |
| 5 | |
| 6 | pub struct ApplicationCommandOptionChoice { |
| 7 | pub: |
| 8 | name string |
| 9 | name_localizations ?map[Locale]string |
| 10 | } |
| 11 | |
| 12 | pub fn ApplicationCommandOptionChoice.parse(j json2.Any) !ApplicationCommandOptionChoice { |
| 13 | match j { |
| 14 | map[string]json2.Any { |
| 15 | return ApplicationCommandOptionChoice{ |
| 16 | name: j['name']! as string |
| 17 | name_localizations: if m := j['name_localizations'] { |
| 18 | maps.to_map[string, json2.Any, Locale, string](m as map[string]json2.Any, fn (k string, v json2.Any) (Locale, string) { |
| 19 | return k, v as string |
| 20 | }) |
| 21 | } else { |
| 22 | none |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | else { |
| 27 | return error('expected application command option choice to be object, got ${j.type_name()}') |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | fn test_main() { |
| 33 | var := ApplicationCommandOptionChoice.parse({ |
| 34 | 'name': json2.Any('foo') |
| 35 | 'name_localizations': { |
| 36 | 'name': json2.Any('foo') |
| 37 | } |
| 38 | })! |
| 39 | assert dump(var) == var |
| 40 | } |
| 41 | |