1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
use crate::app::{
    AppMeta, Autocomplete, AutocompleteSuggestion, CommandAlias, CommandMatches, ContextAwareParse,
    Runnable,
};
use crate::storage::{Change, Record, RepositoryError, StorageCommand};
use crate::utils::{quoted_words, CaseInsensitiveStr};
use crate::world::npc::NpcData;
use crate::world::place::PlaceData;
use crate::world::thing::{Thing, ThingData};
use crate::world::Field;
use async_trait::async_trait;
use futures::join;
use std::fmt;
use std::ops::Range;

mod autocomplete;
mod parse;

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum WorldCommand {
    Create {
        parsed_thing_data: ParsedThing<ThingData>,
    },
    CreateMultiple {
        thing_data: ThingData,
    },
    Edit {
        name: String,
        parsed_diff: ParsedThing<ThingData>,
    },
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ParsedThing<T> {
    pub thing_data: T,
    pub unknown_words: Vec<Range<usize>>,
    pub word_count: usize,
}

#[async_trait(?Send)]
impl Runnable for WorldCommand {
    async fn run(self, input: &str, app_meta: &mut AppMeta) -> Result<String, String> {
        match self {
            Self::Create { parsed_thing_data } => {
                let original_thing_data = parsed_thing_data.thing_data;
                let unknown_words = parsed_thing_data.unknown_words.to_owned();
                let mut output = None;

                for _ in 0..10 {
                    let mut thing_data = original_thing_data.clone();
                    thing_data.regenerate(&mut app_meta.rng, &app_meta.demographics);
                    let mut command_alias = None;

                    let (message, change) = match thing_data.name() {
                        Field::Locked(Some(name)) => {
                            (
                                Some(format!(
                                    "\n\n_Because you specified a name, {name} has been automatically added to your `journal`. Use `undo` to remove {them}._",
                                    name = name,
                                    them = thing_data.gender().them(),
                                )),
                                Change::CreateAndSave { thing_data, uuid: None },
                            )
                        }
                        Field::Unlocked(Some(name)) => {
                            command_alias = Some(CommandAlias::literal(
                                "save",
                                format!("save {}", name),
                                StorageCommand::Save {
                                    name: name.to_string(),
                                }
                                .into(),
                            ));

                            app_meta.command_aliases.insert(CommandAlias::literal(
                                "more",
                                format!("create {}", original_thing_data.display_description()),
                                WorldCommand::CreateMultiple {
                                    thing_data: original_thing_data.clone(),
                                }
                                .into(),
                            ));

                            (
                                Some(format!(
                                    "\n\n_{name} has not yet been saved. Use ~save~ to save {them} to your `journal`. For more suggestions, type ~more~._",
                                    name = name,
                                    them = thing_data.gender().them(),
                                )),
                                Change::Create { thing_data, uuid: None },
                            )
                        }
                        _ => (None, Change::Create { thing_data, uuid: None }),
                    };

                    match app_meta.repository.modify(change).await {
                        Ok(Some(Record { thing, .. })) => {
                            output = Some(format!(
                                "{}{}",
                                thing.display_details(
                                    app_meta
                                        .repository
                                        .load_relations(&thing)
                                        .await
                                        .unwrap_or_default(),
                                ),
                                message.as_ref().map_or("", String::as_str),
                            ));

                            if let Some(alias) = command_alias {
                                app_meta.command_aliases.insert(alias);
                            }

                            break;
                        }

                        Err((
                            Change::Create { thing_data, .. } | Change::CreateAndSave { thing_data, .. },
                            RepositoryError::NameAlreadyExists(other_thing),
                        )) => if thing_data.name().is_locked() {
                            return Err(format!(
                                "That name is already in use by {}.",
                                other_thing.display_summary(),
                            ));
                        },

                        Err((Change::Create { thing_data, .. }, RepositoryError::MissingName)) => return Err(format!("There is no name generator implemented for that type. You must specify your own name using `{} named [name]`.", thing_data.display_description())),

                        Ok(None) | Err(_) => return Err("An error occurred.".to_string()),
                    }
                }

                if let Some(output) = output {
                    Ok(append_unknown_words_notice(output, input, unknown_words))
                } else {
                    Err(format!(
                        "Couldn't create a unique {} name.",
                        original_thing_data.display_description(),
                    ))
                }
            }
            Self::CreateMultiple { thing_data } => {
                let mut output = format!(
                    "# Alternative suggestions for \"{}\"",
                    thing_data.display_description(),
                );

                for i in 1..=10 {
                    let mut thing_output = None;

                    for _ in 0..10 {
                        let mut thing_data = thing_data.clone();
                        thing_data.regenerate(&mut app_meta.rng, &app_meta.demographics);

                        match app_meta
                            .repository
                            .modify(Change::Create {
                                thing_data,
                                uuid: None,
                            })
                            .await
                        {
                            Ok(Some(Record { thing, .. })) => {
                                app_meta.command_aliases.insert(CommandAlias::literal(
                                    (i % 10).to_string(),
                                    format!("load {}", thing.name()),
                                    StorageCommand::Load {
                                        name: thing.name().to_string(),
                                    }
                                    .into(),
                                ));
                                thing_output = Some(format!(
                                    "{}~{}~ {}",
                                    if i == 1 { "\n\n" } else { "\\\n" },
                                    i % 10,
                                    thing.display_summary(),
                                ));
                                break;
                            }
                            Ok(None) | Err((_, RepositoryError::NameAlreadyExists(_))) => {} // silently retry
                            Err(_) => return Err("An error occurred.".to_string()),
                        }
                    }

                    if let Some(thing_output) = thing_output {
                        output.push_str(&thing_output);
                    } else {
                        output.push_str("\n\n! An error occurred generating additional results.");
                        break;
                    }
                }

                app_meta.command_aliases.insert(CommandAlias::literal(
                    "more",
                    format!("create {}", thing_data.display_description()),
                    Self::CreateMultiple { thing_data }.into(),
                ));

                output.push_str("\n\n_For even more suggestions, type ~more~._");

                Ok(output)
            }
            Self::Edit { name, parsed_diff } => {
                let ParsedThing {
                    thing_data: thing_diff,
                    unknown_words,
                    word_count: _,
                } = parsed_diff;

                let thing_type = thing_diff.as_str();

                match app_meta.repository.modify(Change::Edit {
                        name: name.clone(),
                        uuid: None,
                        diff: thing_diff,
                    }).await {
                    Ok(Some(Record { thing, .. })) => Ok(
                        if matches!(app_meta.repository.undo_history().next(), Some(Change::EditAndUnsave { .. })) {
                            format!(
                                "{}\n\n_{} was successfully edited and automatically saved to your `journal`. Use `undo` to reverse this._",
                                thing.display_details(app_meta.repository.load_relations(&thing).await.unwrap_or_default()),
                                name,
                            )
                        } else {
                            format!(
                                "{}\n\n_{} was successfully edited. Use `undo` to reverse this._",
                                thing.display_details(app_meta.repository.load_relations(&thing).await.unwrap_or_default()),
                                name,
                            )
                        }
                    ),
                    Err((_, RepositoryError::NotFound)) => Err(format!(r#"There is no {} named "{}"."#, thing_type, name)),
                    _ => Err(format!("Couldn't edit `{}`.", name)),
                }
                .map(|s| append_unknown_words_notice(s, input, unknown_words))
            }
        }
    }
}

#[async_trait(?Send)]
impl ContextAwareParse for WorldCommand {
    async fn parse_input(input: &str, app_meta: &AppMeta) -> CommandMatches<Self> {
        let mut matches = CommandMatches::default();

        if let Some(Ok(parsed_thing_data)) = input
            .strip_prefix_ci("create ")
            .map(|s| s.parse::<ParsedThing<ThingData>>())
        {
            if parsed_thing_data.unknown_words.is_empty() {
                matches.push_canonical(Self::Create { parsed_thing_data });
            } else {
                matches.push_fuzzy(Self::Create { parsed_thing_data });
            }
        } else if let Ok(parsed_thing_data) = input.parse::<ParsedThing<ThingData>>() {
            matches.push_fuzzy(Self::Create { parsed_thing_data });
        }

        if let Some(word) = quoted_words(input)
            .skip(1)
            .find(|word| word.as_str().eq_ci("is"))
        {
            let (name, description) = (
                input[..word.range().start].trim(),
                input[word.range().end..].trim(),
            );

            let (diff, thing): (Result<ParsedThing<ThingData>, ()>, Option<Thing>) =
                if let Ok(Record { thing, .. }) = app_meta.repository.get_by_name(name).await {
                    (
                        match thing.data {
                            ThingData::Npc(_) => description
                                .parse::<ParsedThing<NpcData>>()
                                .map(|t| t.into_thing_data()),
                            ThingData::Place(_) => description
                                .parse::<ParsedThing<PlaceData>>()
                                .map(|t| t.into_thing_data()),
                        }
                        .or_else(|_| description.parse()),
                        Some(thing),
                    )
                } else {
                    // This will be an error when we try to run the command, but for now we'll pretend
                    // it's valid so that we can provide a more coherent message.
                    (description.parse(), None)
                };

            if let Ok(mut diff) = diff {
                let name = thing
                    .map(|t| t.name().to_string())
                    .unwrap_or_else(|| name.to_string());

                diff.unknown_words.iter_mut().for_each(|range| {
                    *range = range.start + word.range().end + 1..range.end + word.range().end + 1
                });

                matches.push_fuzzy(Self::Edit {
                    name,
                    parsed_diff: diff,
                });
            }
        }

        matches
    }
}

#[async_trait(?Send)]
impl Autocomplete for WorldCommand {
    async fn autocomplete(input: &str, app_meta: &AppMeta) -> Vec<AutocompleteSuggestion> {
        let mut suggestions = Vec::new();

        let (mut place_suggestions, mut npc_suggestions) = join!(
            PlaceData::autocomplete(input, app_meta),
            NpcData::autocomplete(input, app_meta),
        );

        suggestions.append(&mut place_suggestions);
        suggestions.append(&mut npc_suggestions);

        let mut input_words = quoted_words(input).skip(1);

        if let Some((is_word, next_word)) = input_words
            .find(|word| word.as_str().eq_ci("is"))
            .and_then(|word| input_words.next().map(|next_word| (word, next_word)))
        {
            if let Ok(Record { thing, .. }) = app_meta
                .repository
                .get_by_name(input[..is_word.range().start].trim())
                .await
            {
                let split_pos = input.len() - input[is_word.range().end..].trim_start().len();

                let edit_suggestions = match thing.data {
                    ThingData::Npc(_) => {
                        NpcData::autocomplete(input[split_pos..].trim_start(), app_meta)
                    }
                    ThingData::Place(_) => {
                        PlaceData::autocomplete(input[split_pos..].trim_start(), app_meta)
                    }
                }
                .await;

                suggestions.extend(edit_suggestions.into_iter().map(|suggestion| {
                    AutocompleteSuggestion::new(
                        format!("{}{}", &input[..split_pos], suggestion.term),
                        format!("edit {}", thing.as_str()),
                    )
                }));

                if next_word.as_str().in_ci(&["named", "called"]) && input_words.next().is_some() {
                    suggestions.push(AutocompleteSuggestion::new(
                        input.to_string(),
                        format!("rename {}", thing.as_str()),
                    ));
                }
            }
        }

        if let Ok(Record { thing, .. }) = app_meta.repository.get_by_name(input.trim_end()).await {
            suggestions.push(AutocompleteSuggestion::new(
                if input.ends_with(char::is_whitespace) {
                    format!("{}is [{} description]", input, thing.as_str())
                } else {
                    format!("{} is [{} description]", input, thing.as_str())
                },
                format!("edit {}", thing.as_str()),
            ));
        } else if let Some((last_word_index, last_word)) =
            quoted_words(input).enumerate().skip(1).last()
        {
            if "is".starts_with_ci(last_word.as_str()) {
                if let Ok(Record { thing, .. }) = app_meta
                    .repository
                    .get_by_name(input[..last_word.range().start].trim())
                    .await
                {
                    suggestions.push(AutocompleteSuggestion::new(
                        if last_word.range().end == input.len() {
                            format!(
                                "{}is [{} description]",
                                &input[..last_word.range().start],
                                thing.as_str(),
                            )
                        } else {
                            format!("{}[{} description]", &input, thing.as_str())
                        },
                        format!("edit {}", thing.as_str()),
                    ))
                }
            } else if let Some(suggestion) = ["named", "called"]
                .iter()
                .find(|s| s.starts_with_ci(last_word.as_str()))
            {
                let second_last_word = quoted_words(input).nth(last_word_index - 1).unwrap();

                if second_last_word.as_str().eq_ci("is") {
                    if let Ok(Record { thing, .. }) = app_meta
                        .repository
                        .get_by_name(input[..second_last_word.range().start].trim())
                        .await
                    {
                        suggestions.push(AutocompleteSuggestion::new(
                            if last_word.range().end == input.len() {
                                format!(
                                    "{}{} [name]",
                                    &input[..last_word.range().start],
                                    suggestion,
                                )
                            } else {
                                format!("{}[name]", input)
                            },
                            format!("rename {}", thing.as_str()),
                        ));
                    }
                }
            }
        }

        suggestions
    }
}

impl fmt::Display for WorldCommand {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        match self {
            Self::Create { parsed_thing_data } => write!(
                f,
                "create {}",
                parsed_thing_data.thing_data.display_description()
            ),
            Self::CreateMultiple { thing_data } => {
                write!(f, "create  multiple {}", thing_data.display_description())
            }
            Self::Edit { name, parsed_diff } => {
                write!(
                    f,
                    "{} is {}",
                    name,
                    parsed_diff.thing_data.display_description()
                )
            }
        }
    }
}

impl<T: Into<ThingData>> ParsedThing<T> {
    pub fn into_thing_data(self) -> ParsedThing<ThingData> {
        ParsedThing {
            thing_data: self.thing_data.into(),
            unknown_words: self.unknown_words,
            word_count: self.word_count,
        }
    }
}

impl<T: Default> Default for ParsedThing<T> {
    fn default() -> Self {
        Self {
            thing_data: T::default(),
            unknown_words: Vec::default(),
            word_count: 0,
        }
    }
}

impl<T: Into<ThingData>> From<ParsedThing<T>> for ThingData {
    fn from(input: ParsedThing<T>) -> Self {
        input.thing_data.into()
    }
}

fn append_unknown_words_notice(
    mut output: String,
    input: &str,
    unknown_words: Vec<Range<usize>>,
) -> String {
    if !unknown_words.is_empty() {
        output.push_str(
            "\n\n! initiative.sh doesn't know some of those words, but it did its best.\n\n\\> ",
        );

        {
            let mut pos = 0;
            for word_range in unknown_words.iter() {
                output.push_str(&input[pos..word_range.start]);
                pos = word_range.end;
                output.push_str("**");
                output.push_str(&input[word_range.clone()]);
                output.push_str("**");
            }
            output.push_str(&input[pos..]);
        }

        output.push_str("\\\n\u{a0}\u{a0}");

        {
            let mut words = unknown_words.into_iter();
            let mut unknown_word = words.next();
            for (i, _) in input.char_indices() {
                if unknown_word.as_ref().map_or(false, |word| i >= word.end) {
                    unknown_word = words.next();
                }

                if let Some(word) = &unknown_word {
                    output.push(if i >= word.start { '^' } else { '\u{a0}' });
                } else {
                    break;
                }
            }
        }

        output.push_str("\\\nWant to help improve its vocabulary? Join us [on Discord](https://discord.gg/ZrqJPpxXVZ) and suggest your new words!");
    }
    output
}

#[cfg(test)]
mod test {
    use super::*;
    use crate::app::assert_autocomplete;
    use crate::storage::NullDataStore;
    use crate::world::npc::{Age, Gender, NpcData, Species};
    use crate::world::place::{PlaceData, PlaceType};
    use crate::Event;
    use tokio_test::block_on;

    #[test]
    fn parse_input_test() {
        let mut app_meta = app_meta();

        assert_eq!(
            CommandMatches::new_fuzzy(create(NpcData::default())),
            block_on(WorldCommand::parse_input("npc", &app_meta)),
        );

        assert_eq!(
            CommandMatches::new_canonical(create(NpcData::default())),
            block_on(WorldCommand::parse_input("create npc", &app_meta)),
        );

        assert_eq!(
            CommandMatches::new_fuzzy(create(NpcData {
                species: Species::Elf.into(),
                ..Default::default()
            })),
            block_on(WorldCommand::parse_input("elf", &app_meta)),
        );

        assert_eq!(
            CommandMatches::default(),
            block_on(WorldCommand::parse_input("potato", &app_meta)),
        );

        {
            block_on(
                app_meta.repository.modify(Change::Create {
                    thing_data: NpcData {
                        name: "Spot".into(),
                        ..Default::default()
                    }
                    .into(),
                    uuid: None,
                }),
            )
            .unwrap();

            assert_eq!(
                CommandMatches::new_fuzzy(WorldCommand::Edit {
                    name: "Spot".into(),
                    parsed_diff: ParsedThing {
                        thing_data: NpcData {
                            age: Age::Child.into(),
                            gender: Gender::Masculine.into(),
                            ..Default::default()
                        }
                        .into(),
                        #[expect(clippy::single_range_in_vec_init)]
                        unknown_words: vec![10..14],
                        word_count: 2,
                    },
                }),
                block_on(WorldCommand::parse_input("Spot is a good boy", &app_meta)),
            );
        }
    }

    #[test]
    fn autocomplete_test() {
        let mut app_meta = app_meta();

        block_on(
            app_meta.repository.modify(Change::Create {
                thing_data: NpcData {
                    name: "Potato Johnson".into(),
                    species: Species::Elf.into(),
                    gender: Gender::NonBinaryThey.into(),
                    age: Age::Adult.into(),
                    ..Default::default()
                }
                .into(),
                uuid: None,
            }),
        )
        .unwrap();

        [
            ("npc", "create person"),
            // Species
            ("dragonborn", "create dragonborn"),
            ("dwarf", "create dwarf"),
            ("elf", "create elf"),
            ("gnome", "create gnome"),
            ("half-elf", "create half-elf"),
            ("half-orc", "create half-orc"),
            ("halfling", "create halfling"),
            ("human", "create human"),
            ("tiefling", "create tiefling"),
            // PlaceType
            ("inn", "create inn"),
        ]
        .into_iter()
        .for_each(|(word, summary)| {
            assert_eq!(
                vec![AutocompleteSuggestion::new(word, summary)],
                block_on(WorldCommand::autocomplete(word, &app_meta)),
            );

            assert_eq!(
                vec![AutocompleteSuggestion::new(word, summary)],
                block_on(WorldCommand::autocomplete(&word.to_uppercase(), &app_meta)),
            );
        });

        assert_autocomplete(
            &[
                ("baby", "create infant"),
                ("bakery", "create bakery"),
                ("bank", "create bank"),
                ("bar", "create bar"),
                ("barony", "create barony"),
                ("barracks", "create barracks"),
                ("barrens", "create barrens"),
                ("base", "create base"),
                ("bathhouse", "create bathhouse"),
                ("beach", "create beach"),
                ("blacksmith", "create blacksmith"),
                ("boy", "create child, he/him"),
                ("brewery", "create brewery"),
                ("bridge", "create bridge"),
                ("building", "create building"),
                ("business", "create business"),
            ][..],
            block_on(WorldCommand::autocomplete("b", &app_meta)),
        );

        assert_autocomplete(
            &[(
                "Potato Johnson is [character description]",
                "edit character",
            )][..],
            block_on(WorldCommand::autocomplete("Potato Johnson", &app_meta)),
        );

        assert_autocomplete(
            &[(
                "Potato Johnson is a [character description]",
                "edit character",
            )][..],
            block_on(WorldCommand::autocomplete(
                "Potato Johnson is a ",
                &app_meta,
            )),
        );

        assert_autocomplete(
            &[
                ("Potato Johnson is an elderly", "edit character"),
                ("Potato Johnson is an elf", "edit character"),
                ("Potato Johnson is an elvish", "edit character"),
                ("Potato Johnson is an enby", "edit character"),
            ][..],
            block_on(WorldCommand::autocomplete(
                "Potato Johnson is an e",
                &app_meta,
            )),
        );
    }

    #[test]
    fn display_test() {
        let app_meta = app_meta();

        [
            create(PlaceData {
                subtype: "inn".parse::<PlaceType>().ok().into(),
                ..Default::default()
            }),
            create(NpcData::default()),
            create(NpcData {
                species: Some(Species::Elf).into(),
                ..Default::default()
            }),
        ]
        .into_iter()
        .for_each(|command| {
            let command_string = command.to_string();
            assert_ne!("", command_string);

            assert_eq!(
                CommandMatches::new_canonical(command.clone()),
                block_on(WorldCommand::parse_input(&command_string, &app_meta)),
                "{}",
                command_string,
            );

            assert_eq!(
                CommandMatches::new_canonical(command),
                block_on(WorldCommand::parse_input(
                    &command_string.to_uppercase(),
                    &app_meta
                )),
                "{}",
                command_string.to_uppercase(),
            );
        });
    }

    fn parsed_thing(thing_data: impl Into<ThingData>) -> ParsedThing<ThingData> {
        ParsedThing {
            thing_data: thing_data.into(),
            unknown_words: Vec::new(),
            word_count: 1,
        }
    }

    fn create(thing_data: impl Into<ThingData>) -> WorldCommand {
        WorldCommand::Create {
            parsed_thing_data: parsed_thing(thing_data),
        }
    }

    fn event_dispatcher(_event: Event) {}

    fn app_meta() -> AppMeta {
        AppMeta::new(NullDataStore, &event_dispatcher)
    }
}