shared/domain/module/
body.rs

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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
#![allow(missing_docs)]

use super::ModuleKind;
use crate::{
    domain::{audio::AudioId, image::ImageId},
    media::MediaLibrary,
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{
    collections::HashSet,
    fmt::{self, Debug},
    hash::Hash,
};
use strum_macros::{EnumIs, EnumIter, IntoStaticStr};

/// Memory Game Body.
pub mod memory;

/// Talking Poster Body.
pub mod poster;

/// Video Body.
pub mod video;

/// Embed Body.
pub mod embed;

/// Listen & Learn Body.
pub mod tapping_board;

/// Drag & Drop Body.
pub mod drag_drop;

/// Cover Body.
pub mod cover;

/// Resource Cover Body.
pub mod resource_cover;

/// Flashcards .
pub mod flashcards;

/// Quiz Game
pub mod card_quiz;

/// Matching
pub mod matching;

/// Answer This (Previously Find the Answer)
pub mod find_answer;

/// Legacy
pub mod legacy;

/// Groups that share types
pub mod _groups;

/// Body kinds for Modules.
#[derive(Clone, Serialize, Deserialize, Debug, strum_macros::EnumTryAs)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub enum Body {
    /// Module is a memory game, and has a memory game's body.
    MemoryGame(memory::ModuleData),

    /// Module is matching game, and has a matching game's body.
    Matching(matching::ModuleData),

    /// Module is flashcards, and has a flashcard's body.
    Flashcards(flashcards::ModuleData),

    /// Module is a quiz game, and has a quiz game's body.
    CardQuiz(card_quiz::ModuleData),

    /// Module is a poster, and has a talking poster's body.
    Poster(poster::ModuleData),

    /// Module is a Video, and has a video body.
    Video(video::ModuleData),

    /// Module is a Embed, and has a embed body.
    Embed(embed::ModuleData),

    /// Module is a Listen & Learn, and has a Listen & Learn's body.
    TappingBoard(tapping_board::ModuleData),

    /// Module is a drag & drop, and has a drag & drop's body.
    DragDrop(drag_drop::ModuleData),

    /// Module is a [`Cover`](super::ModuleKind::Cover).
    ///
    /// Cover for Module type
    Cover(cover::ModuleData),

    /// Module is a Resource Cover.
    ResourceCover(resource_cover::ModuleData),

    /// Module is a Answer This (Find the Answer), and has Answer This's (Find the Answer)'s body.
    FindAnswer(find_answer::ModuleData),

    /// Module is a legacy, and has a legacy's body.
    Legacy(legacy::ModuleData),
}

impl Body {
    /// create a new Body for a given ModuleKind
    pub fn new(kind: super::ModuleKind) -> Self {
        match kind {
            super::ModuleKind::Cover => Self::Cover(Default::default()),
            super::ModuleKind::ResourceCover => Self::ResourceCover(Default::default()),
            super::ModuleKind::Memory => Self::MemoryGame(Default::default()),
            super::ModuleKind::CardQuiz => Self::CardQuiz(Default::default()),
            super::ModuleKind::Flashcards => Self::Flashcards(Default::default()),
            super::ModuleKind::Matching => Self::Matching(Default::default()),
            super::ModuleKind::Poster => Self::Poster(Default::default()),
            super::ModuleKind::Video => Self::Video(Default::default()),
            super::ModuleKind::Embed => Self::Embed(Default::default()),
            super::ModuleKind::TappingBoard => Self::TappingBoard(Default::default()),
            super::ModuleKind::DragDrop => Self::DragDrop(Default::default()),
            super::ModuleKind::FindAnswer => Self::FindAnswer(Default::default()),
            super::ModuleKind::Legacy => Self::Legacy(Default::default()),
            super::ModuleKind::Tracing => unimplemented!("TODO!"),
        }
    }

    /// Convert this container to a Body wrapper of a specific kind
    pub fn convert_to_body(&self, kind: ModuleKind) -> Result<Self, &'static str> {
        match self {
            Self::MemoryGame(data) => data.convert_to_body(kind),
            Self::Matching(data) => data.convert_to_body(kind),
            Self::Flashcards(data) => data.convert_to_body(kind),
            Self::CardQuiz(data) => data.convert_to_body(kind),
            Self::Poster(data) => data.convert_to_body(kind),
            Self::Video(data) => data.convert_to_body(kind),
            Self::Embed(data) => data.convert_to_body(kind),
            Self::TappingBoard(data) => data.convert_to_body(kind),
            Self::DragDrop(data) => data.convert_to_body(kind),
            Self::Cover(data) => data.convert_to_body(kind),
            Self::ResourceCover(data) => data.convert_to_body(kind),
            Self::FindAnswer(data) => data.convert_to_body(kind),
            Self::Legacy(data) => data.convert_to_body(kind),
        }
    }

    /// Helper to check whether the inner data is complete
    pub fn is_complete(&self) -> bool {
        match self {
            Self::MemoryGame(data) => data.is_complete(),
            Self::Matching(data) => data.is_complete(),
            Self::Flashcards(data) => data.is_complete(),
            Self::CardQuiz(data) => data.is_complete(),
            Self::Poster(data) => data.is_complete(),
            Self::Video(data) => data.is_complete(),
            Self::Embed(data) => data.is_complete(),
            Self::TappingBoard(data) => data.is_complete(),
            Self::DragDrop(data) => data.is_complete(),
            Self::Cover(data) => data.is_complete(),
            Self::ResourceCover(data) => data.is_complete(),
            Self::FindAnswer(data) => data.is_complete(),
            Self::Legacy(data) => data.is_complete(),
        }
    }
}

/// Extension trait for interop
/// impl on inner body data
pub trait BodyExt<Mode: ModeExt, Step: StepExt>:
    BodyConvert + TryFrom<Body> + Serialize + DeserializeOwned + Clone + Debug
{
    /// get choose mode list. By default it's the full list
    /// but that can be overridden to re-order or hide some modes
    fn choose_mode_list() -> Vec<Mode> {
        Mode::get_list()
    }

    /// get self as a Body
    fn as_body(&self) -> Body;

    /// is complete
    fn is_complete(&self) -> bool;

    /// is legacy
    fn is_legacy() -> bool {
        false
    }

    /// should wait for manual phase change to Init
    fn has_preload() -> bool {
        false
    }

    /// get the kind from the type itself
    fn kind() -> super::ModuleKind;

    /// given a Mode, get a new Self
    /// will usually populate an inner .content
    fn new_with_mode_and_theme(mode: Mode, theme_id: ThemeId) -> Self;

    /// Fetch the mode for this module
    fn mode(&self) -> Option<Mode>;

    /// requires an additional step of choosing the mode
    fn requires_choose_mode(&self) -> bool;

    /// Get the current theme
    fn get_theme(&self) -> Option<ThemeId>;

    /// Set the current theme
    fn set_theme(&mut self, theme_id: ThemeId);

    /// Set editor state step
    fn set_editor_state_step(&mut self, step: Step);
    /// Set editor state steps completed
    fn set_editor_state_steps_completed(&mut self, steps_completed: HashSet<Step>);
    /// Get editor state step
    fn get_editor_state_step(&self) -> Option<Step>;
    /// Get editor state steps completed
    fn get_editor_state_steps_completed(&self) -> Option<HashSet<Step>>;
    /// Insert a completed step
    fn insert_editor_state_step_completed(&mut self, step: Step) {
        if let Some(mut steps_completed) = self.get_editor_state_steps_completed() {
            steps_completed.insert(step);
            self.set_editor_state_steps_completed(steps_completed);
        }
    }

    /// Convert this inner data to a Body wrapper of a specific kind
    fn convert_to_body(&self, kind: ModuleKind) -> Result<Body, &'static str> {
        match kind {
            ModuleKind::Memory => Ok(Body::MemoryGame(self.convert_to_memory()?)),
            ModuleKind::Matching => Ok(Body::Matching(self.convert_to_matching()?)),
            ModuleKind::Flashcards => Ok(Body::Flashcards(self.convert_to_flashcards()?)),
            ModuleKind::CardQuiz => Ok(Body::CardQuiz(self.convert_to_card_quiz()?)),
            ModuleKind::Poster => Ok(Body::Poster(self.convert_to_poster()?)),
            ModuleKind::Video => Ok(Body::Video(self.convert_to_video()?)),
            ModuleKind::Embed => Ok(Body::Embed(self.convert_to_embed()?)),
            ModuleKind::TappingBoard => Ok(Body::TappingBoard(self.convert_to_tapping_board()?)),
            ModuleKind::DragDrop => Ok(Body::DragDrop(self.convert_to_drag_drop()?)),
            ModuleKind::Cover => Ok(Body::Cover(self.convert_to_cover()?)),
            ModuleKind::ResourceCover => Ok(Body::ResourceCover(self.convert_to_resource_cover()?)),
            ModuleKind::FindAnswer => Ok(Body::FindAnswer(self.convert_to_find_answer()?)),
            ModuleKind::Legacy => Ok(Body::Legacy(self.convert_to_legacy()?)),
            _ => unimplemented!(
                "cannot convert from {} to {}",
                Self::kind().as_str(),
                kind.as_str()
            ),
        }
    }
}

/// These will all error by default.
/// Modules that can be converted between eachother must override
/// The relevant methods
pub trait BodyConvert {
    /// Get a list of valid conversion targets
    fn convertable_list() -> Vec<ModuleKind> {
        Vec::new()
    }
    /// Memory game
    fn convert_to_memory(&self) -> Result<memory::ModuleData, &'static str> {
        Err("cannot convert to memory game!")
    }
    /// Matching
    fn convert_to_matching(&self) -> Result<matching::ModuleData, &'static str> {
        Err("cannot convert to matching!")
    }
    /// Flashcards
    fn convert_to_flashcards(&self) -> Result<flashcards::ModuleData, &'static str> {
        Err("cannot convert to matching!")
    }
    /// Quiz game
    fn convert_to_card_quiz(&self) -> Result<card_quiz::ModuleData, &'static str> {
        Err("cannot convert to quiz game!")
    }
    /// Talking Poster
    fn convert_to_poster(&self) -> Result<poster::ModuleData, &'static str> {
        Err("cannot convert to talking poster!")
    }
    /// Listen & Learn
    fn convert_to_tapping_board(&self) -> Result<tapping_board::ModuleData, &'static str> {
        Err("cannot convert to Listen & Learn!")
    }
    /// Drag & Drop
    fn convert_to_drag_drop(&self) -> Result<drag_drop::ModuleData, &'static str> {
        Err("cannot convert to drag & drop!")
    }
    /// Cover
    fn convert_to_cover(&self) -> Result<cover::ModuleData, &'static str> {
        Err("cannot convert to cover!")
    }
    /// Resource Cover
    fn convert_to_resource_cover(&self) -> Result<resource_cover::ModuleData, &'static str> {
        Err("cannot convert to resource cover!")
    }
    /// Resource Cover
    fn convert_to_find_answer(&self) -> Result<find_answer::ModuleData, &'static str> {
        Err("cannot convert to answer this!")
    }
    /// Video
    fn convert_to_video(&self) -> Result<video::ModuleData, &'static str> {
        Err("cannot convert to video!")
    }
    /// Embed
    fn convert_to_embed(&self) -> Result<embed::ModuleData, &'static str> {
        Err("cannot convert to embed!")
    }
    /// Legacy
    fn convert_to_legacy(&self) -> Result<legacy::ModuleData, &'static str> {
        Err("cannot convert to legacy!")
    }
}

/// Extenstion trait for modes
pub trait ModeExt: Copy + Default + PartialEq + Eq + Hash {
    /// get a list of all the modes
    /// (becomes the default in Choose page, which can be overriden in BodyExt)
    fn get_list() -> Vec<Self>;

    /// get the mode itself as a string id
    fn as_str_id(&self) -> &'static str;
    /// for headers, labels, etc.
    fn label(&self) -> &'static str;

    /// Image tag filters for search
    /// The actual ImageTag enum variants are in components
    fn image_tag_filters(&self) -> Option<Vec<i16>> {
        None
    }

    /// Image tag priorities for search
    /// The actual ImageTag enum variants are in components
    fn image_tag_priorities(&self) -> Option<Vec<i16>> {
        None
    }
}

/// impl ModeExt for empty modes
/// this is a special case and should only be used
/// where the module genuinely ignores the mode
/// one example is the Cover module
impl ModeExt for () {
    fn get_list() -> Vec<Self> {
        vec![]
    }

    fn as_str_id(&self) -> &'static str {
        ""
    }

    fn label(&self) -> &'static str {
        ""
    }
}

impl Body {
    /// Gets this body's related [`ModuleKind`](super::ModuleKind)
    pub fn kind(&self) -> super::ModuleKind {
        match self {
            Self::Cover(_) => super::ModuleKind::Cover,
            Self::ResourceCover(_) => super::ModuleKind::ResourceCover,
            Self::MemoryGame(_) => super::ModuleKind::Memory,
            Self::Flashcards(_) => super::ModuleKind::Flashcards,
            Self::CardQuiz(_) => super::ModuleKind::CardQuiz,
            Self::Matching(_) => super::ModuleKind::Matching,
            Self::Poster(_) => super::ModuleKind::Poster,
            Self::Video(_) => super::ModuleKind::Video,
            Self::Embed(_) => super::ModuleKind::Embed,
            Self::TappingBoard(_) => super::ModuleKind::TappingBoard,
            Self::DragDrop(_) => super::ModuleKind::DragDrop,
            Self::FindAnswer(_) => super::ModuleKind::FindAnswer,
            Self::Legacy(_) => super::ModuleKind::Legacy,
        }
    }
}

/* The following are things which are often used by multiple modules */

/// Generic editor state which must be preserved between sessions
/// Although these are saved to the db, they aren't relevant for playback
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
pub struct EditorState<STEP>
where
    STEP: StepExt,
{
    /// the current step
    pub step: STEP,

    /// the completed steps
    pub steps_completed: HashSet<STEP>,
}

/// This extension trait makes it possible to keep the Step
/// functionality generic and at a higher level than the module itself
pub trait StepExt: Clone + Copy + Default + PartialEq + Eq + Hash + Debug + Unpin {
    /// Get the next step from current step
    fn next(&self) -> Option<Self>;
    /// Get the step as a number
    fn as_number(&self) -> usize;
    /// Label to display (will be localized)
    fn label(&self) -> &'static str;
    /// List of all available steps
    fn get_list() -> Vec<Self>;
    /// Get the step which is synonymous with "preview"
    /// TODO: this could probably be derived as a combo
    /// of get_list() and next() (i.e. the first step to return None)
    fn get_preview() -> Self;
    /// Auto-implemented, check whether current step is "preview"
    fn is_preview(&self) -> bool {
        *self == Self::get_preview()
    }
}

/// impl StepExt for empty steps
/// this is a special case and should only be used
/// where the module genuinely ignores the step
/// one example is the Legacy module
impl StepExt for () {
    fn next(&self) -> Option<Self> {
        None
    }
    fn as_number(&self) -> usize {
        0
    }
    fn label(&self) -> &'static str {
        ""
    }
    fn get_list() -> Vec<Self> {
        Vec::new()
    }
    fn get_preview() -> Self {
        ()
    }
}

#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq)]
/// Audio
pub struct Audio {
    /// The Audio Id
    pub id: AudioId,
    /// The Media Library
    pub lib: MediaLibrary,
}

/// Module-specific assistance during play.
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
pub struct ModuleAssist {
    /// Text displayed in banner
    pub text: Option<String>,
    /// Audio played on module start
    pub audio: Option<Audio>,
    /// Whether to always show module assistance
    ///
    /// This will override the default module assist behavior.
    ///
    /// Note: This value will never be persisted in the backend.
    #[serde(default)]
    #[cfg_attr(feature = "backend", serde(skip))]
    pub always_show: bool,
}

impl ModuleAssist {
    /// Create a new ModuleAssist instance which doesn't override module assist behavior
    pub fn new(text: Option<String>, audio: Option<Audio>) -> Self {
        Self {
            text,
            audio,
            ..Default::default()
        }
    }

    /// Override default module assist behavior
    pub fn always_show(mut self) -> Self {
        self.always_show = true;
        self
    }

    /// Whether the instructions actually have either text or audio content set
    pub fn has_content(&self) -> bool {
        self.text.is_some() || self.audio.is_some()
    }
}

/// Type of assistance to be shown. This is only set during play and should never be
/// persisted to the database.
#[derive(Clone, Serialize, Deserialize, Debug)]
pub enum ModuleAssistType {
    /// Instructions to be shown when an activity starts
    Instructions,
    /// Feedback to be shown at the end of an activity
    Feedback,
    /// Replayable activity-specific assistance.
    InActivity,
}

impl ModuleAssistType {
    /// Whether this variant is `Instructions`
    pub fn is_instructions(&self) -> bool {
        matches!(self, Self::Instructions)
    }

    /// Whether this variant is `Feedback`
    pub fn is_feedback(&self) -> bool {
        matches!(self, Self::Feedback)
    }

    /// Whether this variant is `InActivity`
    pub fn is_in_activity(&self) -> bool {
        matches!(self, Self::InActivity)
    }
}

#[derive(Clone, Serialize, Deserialize, Debug)]
/// Background
pub enum Background {
    /// Color
    Color(Option<rgb::RGBA8>),
    /// Any other image
    Image(Image),
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
/// Images need id and lib
pub struct Image {
    /// The Image Id
    pub id: ImageId,
    /// The MediaLibrary
    pub lib: MediaLibrary,
}

#[derive(Clone, Default, Serialize, Deserialize, Debug, PartialEq)]
/// Vector of 2 floats
pub struct Vec2(pub [f64; 2]);

impl From<(f64, f64)> for Vec2 {
    fn from((x, y): (f64, f64)) -> Self {
        Self([x, y])
    }
}

impl From<Vec2> for (f64, f64) {
    fn from(v: Vec2) -> Self {
        (v.0[0], v.0[1])
    }
}

#[derive(Clone, Default, Serialize, Deserialize, Debug, PartialEq)]
/// Vector of 3 floats
pub struct Vec3(pub [f64; 3]);

impl From<(f64, f64, f64)> for Vec3 {
    fn from((x, y, z): (f64, f64, f64)) -> Self {
        Self([x, y, z])
    }
}

impl From<Vec3> for (f64, f64, f64) {
    fn from(v: Vec3) -> Self {
        (v.0[0], v.0[1], v.0[2])
    }
}

#[derive(Clone, Default, Serialize, Deserialize, Debug, PartialEq)]
/// Vector of 4 floats, also used as a Quaternion
pub struct Vec4(pub [f64; 4]);

impl From<(f64, f64, f64, f64)> for Vec4 {
    fn from((x, y, z, w): (f64, f64, f64, f64)) -> Self {
        Self([x, y, z, w])
    }
}

impl From<Vec4> for (f64, f64, f64, f64) {
    fn from(v: Vec4) -> Self {
        (v.0[0], v.0[1], v.0[2], v.0[3])
    }
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
/// Visual Transform
pub struct Transform {
    /// Translation
    pub translation: Vec3,
    /// Rotation Quaternion
    pub rotation: Vec4,
    /// Scale for each axis
    pub scale: Vec3,
    /// Origin
    pub origin: Vec3,
}

impl Transform {
    /// Create a new Transform
    pub fn identity() -> Self {
        Self {
            translation: Vec3([0.0, 0.0, 0.0]),
            rotation: Vec4([0.0, 0.0, 0.0, 1.0]),
            scale: Vec3([1.0, 1.0, 1.0]),
            origin: Vec3([0.0, 0.0, 0.0]),
        }
    }
}

impl Default for Transform {
    fn default() -> Self {
        Self::identity()
    }
}

#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, EnumIs)]
pub enum HoverAnimation {
    Grow,
    Tilt,
    Buzz,
}

impl fmt::Display for HoverAnimation {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let str = match self {
            HoverAnimation::Grow => "Grow",
            HoverAnimation::Tilt => "Tilt",
            HoverAnimation::Buzz => "Buzz",
        };
        write!(f, "{str}")
    }
}

impl HoverAnimation {
    pub fn as_str(&self) -> &'static str {
        match self {
            HoverAnimation::Grow => "grow",
            HoverAnimation::Tilt => "tilt",
            HoverAnimation::Buzz => "buzz",
        }
    }
}

#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, EnumIs)]
pub enum StickerHidden {
    OnClick(ShowHideAnimation),
    UntilClick(ShowHideAnimation),
}

#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, EnumIs, EnumIter, Default)]
pub enum ShowHideAnimation {
    #[default]
    Appear,
    FadeInTop,
    FadeInBottom,
    FadeInLeft,
    FadeInRight,
}

impl fmt::Display for ShowHideAnimation {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                ShowHideAnimation::Appear => "Appear",
                ShowHideAnimation::FadeInTop => "Top",
                ShowHideAnimation::FadeInBottom => "Bottom",
                ShowHideAnimation::FadeInLeft => "Left",
                ShowHideAnimation::FadeInRight => "Right",
            }
        )
    }
}

impl ShowHideAnimation {
    pub fn as_str(&self) -> &'static str {
        match self {
            ShowHideAnimation::Appear => "Appear",
            ShowHideAnimation::FadeInTop => "fade-in-top",
            ShowHideAnimation::FadeInBottom => "fade-in-bottom",
            ShowHideAnimation::FadeInLeft => "fade-in-left",
            ShowHideAnimation::FadeInRight => "fade-in-right",
        }
    }
}

/// Theme Ids. Used in various modules
/// See the frontend extension trait for more info
#[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug, EnumIter, IntoStaticStr)]
#[repr(i16)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[allow(missing_docs)]
#[strum(serialize_all = "kebab-case")]
pub enum ThemeId {
    Blank,
    Jigzi,
    JigziGreen,
    JigziBlue,
    JigziRed,
    Chalkboard,
    Iml,
    HebrewReading,
    MyNotebook,
    BackToSchool,
    BackToSchoolYouth,
    MyWorkspace,
    Comix,
    Surreal,
    Abstract,
    Denim,
    HappyBrush,
    Graffiti,
    JewishText,
    NumberGames,
    WonderLab,
    ShabbatShalom,
    RoshHashana,
    RoshHashanah,
    AppleWithHoney,
    Pomegranate,
    YomKippur,
    HappySukkot,
    Sukkot,
    #[strum(serialize = "tubishvat")]
    TuBishvat,
    IlluminatingHanukkah,
    Chanukah,
    ChanukahLights,
    Purim,
    PurimFeast,
    PurimSweets,
    HappyPassover,
    #[strum(serialize = "passover-matza")]
    PassoveMatza,
    PassoverSeder,
    LagBaOmer,
    HappyShavuot,
    ShavuotDishes,
    ShavuotFields,
    OurIsrael,
    Israel,
    JerusalemCity,
    JerusalemWall,
    NoahsArk,
    GardenOfEden,
    JewishStories,
    LovelySpring,
    Spring,
    Flowers,
    Nature,
    SillyMonsters,
    DinoGames,
    WatermelonSummer,
    SummerPool,
    ExcitingFall,
    Autumn,
    WinterSnow,
    IceAge,
    LostInSpace,
    Space,
    Camping,
    HappyBirthday,
    #[strum(serialize = "valentine_s-day")]
    Valentine,
    Jungle,
    OurPlanet,
    Theater,
    Sport,
    Travel,
}

impl Default for ThemeId {
    fn default() -> Self {
        Self::Blank
    }
}