stry_common/models/
story.rs

1//! Entities for the story 'module', everything tags unique to a story or
2//! series is here.
3
4use {
5    crate::models::{
6        core::{Comment, Part, User},
7        Existing, Id,
8    },
9    either::Either,
10};
11
12#[rustfmt::skip]
13#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
14#[derive(serde::Deserialize, serde::Serialize)]
15pub struct Story {
16    /// The title of the story, this is not unique as stories are tracked
17    /// with its `Id`.
18    pub name: String,
19    pub summary: String,
20
21    pub rating: Rating,
22    pub state: State,
23
24    pub authors: Vec<Existing<User>>,
25    pub commissioners: Vec<Existing<User>>,
26    pub dedicatees: Vec<Existing<User>>,
27
28    pub origins: Vec<Existing<Origin>>,
29    pub warnings: Vec<Existing<Warning>>,
30    pub pairings: Vec<Existing<Pairing>>,
31    pub characters: Vec<Existing<Character>>,
32    pub tags: Vec<Existing<Tag>>,
33
34    /// # Variant
35    ///
36    /// Is `None` when this type is used indirectly (ie in another entity).
37    pub series: Option<Existing<Series>>,
38
39    /// # Variant
40    ///
41    /// Is `None` when this type is used indirectly (ie in another entity).
42    pub chapters: Option<Either<Vec<Existing<Chapter>>, Vec<Id>>>,
43
44    /// THe sum of all of the chapter's word counts.
45    ///
46    /// # Database Implementation
47    ///
48    /// Do not actually store the value in the database, let it be counted at run time.
49    pub words: i32,
50
51    pub comments: Vec<Existing<Comment>>,
52}
53
54#[rustfmt::skip]
55#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
56#[derive(serde::Deserialize, serde::Serialize)]
57pub struct Chapter {
58    /// The title of the chapter.
59    ///
60    /// # Variant
61    ///
62    /// To display use the default title (`Chapter {number}`) if is [`None`].
63    pub name: Option<String>,
64
65    /// Marks the chapter was published allowing non authors to view it.
66    ///
67    /// # Note
68    ///
69    /// Even when `true` a chapter can still be edited.
70    pub published: bool,
71
72    /// The parts the make up the beginning author's note.
73    ///
74    /// # Note
75    ///
76    /// This does not contribute to word count.
77    pub prefix: Vec<Existing<Part>>,
78
79    /// THe parts of the actual chapter itself.
80    pub main: Vec<Existing<Part>>,
81
82    /// The parts the make up the ending author's note.
83    ///
84    /// # Note
85    ///
86    /// This does not contribute to word count.
87    pub suffix: Vec<Existing<Part>>,
88
89    /// Comments on the chapter itself not its parts.
90    pub comments: Vec<Existing<Comment>>,
91
92    /// The sum of all the [`main`] parts word count.
93    ///
94    /// # Database Implementation
95    ///
96    /// Do not actually store the value in the database, let it be counted at run time.
97    ///
98    /// [`main`]: #structfield.main
99    pub words: i64,
100}
101
102#[rustfmt::skip]
103#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
104#[derive(serde::Deserialize, serde::Serialize)]
105pub struct Series {
106    /// The title of the series, this is not unique as series are tracked
107    /// with its `Id`.
108    pub name: String,
109
110    pub summary: String,
111
112    pub state: State,
113
114    /// # Variant
115    ///
116    /// Is `Left` when its used directly and is `Left` when its used indirectly (ie in another entity).
117    pub stories: Either<Vec<Existing<Story>>, Vec<Id>>,
118}
119
120#[rustfmt::skip]
121#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
122#[derive(serde::Deserialize, serde::Serialize)]
123pub struct Character {
124    pub content: String,
125
126    pub description: String,
127}
128
129#[rustfmt::skip]
130#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
131#[derive(serde::Deserialize, serde::Serialize)]
132pub struct Origin {
133    pub content: String,
134
135    pub description: String,
136}
137
138#[rustfmt::skip]
139#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
140#[derive(serde::Deserialize, serde::Serialize)]
141pub struct Pairing {
142    pub hash: String,
143
144    pub relationship: Relationship,
145
146    pub characters: Vec<Existing<Character>>,
147}
148
149#[rustfmt::skip]
150#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
151#[derive(serde::Deserialize, serde::Serialize)]
152pub enum Relationship {
153    Family,
154    Friends,
155    Romantic,
156}
157
158#[rustfmt::skip]
159#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
160#[derive(serde::Deserialize, serde::Serialize)]
161pub struct Tag {
162    pub content: String,
163
164    pub description: String,
165}
166
167#[rustfmt::skip]
168#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
169#[derive(serde::Deserialize, serde::Serialize)]
170pub struct Warning {
171    pub content: String,
172
173    pub description: String,
174}
175
176#[rustfmt::skip]
177#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
178#[derive(serde::Deserialize, serde::Serialize)]
179pub enum Rating {
180    Explicit,
181    Mature,
182    Teen,
183    General,
184}
185
186/// The story's state.
187///
188/// # Note
189///
190/// Stories will automatically become [`State::Abandoned`] if they are left
191/// without modification for some time.
192///
193/// To get this time check the `story-auto-abandon` setting key.
194#[rustfmt::skip]
195#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
196#[derive(serde::Deserialize, serde::Serialize)]
197pub enum State {
198    Completed,
199    InProgress,
200    Hiatus,
201    Abandoned,
202}