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
use crate::create_new::CreateNew;
use crate::fillable::{Fillable, Filler};
use crate::SchemaExample;
use df_st_derive::{Fillable, Filler, HashAndPartialEqById};
use juniper::GraphQLObject;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// A written work that was create at some point in its history in the world.
/// This reference to what is written not the book itself.
#[derive(
    Serialize,
    Deserialize,
    Clone,
    Debug,
    HashAndPartialEqById,
    Fillable,
    Filler,
    Default,
    JsonSchema,
    GraphQLObject,
)]
pub struct WrittenContent {
    /// Identifier for the written form.
    /// `id` must be unique for the whole world.
    pub id: i32,
    pub title: Option<String>,
    pub author_hf_id: Option<i32>,
    pub author_roll: Option<i32>,
    pub form: Option<String>,
    pub form_id: Option<i32>,
    pub page_start: Option<i32>,
    pub page_end: Option<i32>,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    pub style: Vec<WCStyle>,
    pub author: Option<i32>,
    pub reference: Vec<WCReference>,
}

/// A reference (in a written work) to some other object in the world.
#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct WCReference {
    pub written_content_parent_id: i32,
    /// Assigned after parsing
    pub local_id: i32,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    pub type_id: Option<i32>,

    pub written_content_id: Option<i32>,
    pub he_id: Option<i32>,
    pub site_id: Option<i32>,
    pub poetic_form_id: Option<i32>,
    pub musical_form_id: Option<i32>,
    pub dance_form_id: Option<i32>,
    pub hf_id: Option<i32>,
    pub entity_id: Option<i32>,
    pub artifact_id: Option<i32>,
    pub subregion_id: Option<i32>,
}

/// The style of a written work.
#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct WCStyle {
    pub written_content_id: i32,
    /// Assigned after parsing
    pub local_id: i32,
    // #[serde(alias = "type")]
    pub label: Option<String>,
    pub weight: Option<i32>,
}

impl PartialEq for WCReference {
    fn eq(&self, other: &Self) -> bool {
        self.written_content_parent_id == other.written_content_parent_id
            && self.local_id == other.local_id
    }
}

impl std::hash::Hash for WCReference {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.written_content_parent_id.hash(state);
        self.local_id.hash(state);
    }
}

impl PartialEq for WCStyle {
    fn eq(&self, other: &Self) -> bool {
        self.written_content_id == other.written_content_id && self.local_id == other.local_id
    }
}

impl std::hash::Hash for WCStyle {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.written_content_id.hash(state);
        self.local_id.hash(state);
    }
}

impl WrittenContent {
    pub fn new() -> Self {
        Self::default()
    }
}

impl CreateNew for WrittenContent {
    fn new_by_id(id: i32) -> Self {
        Self {
            id,
            ..Default::default()
        }
    }
}

impl SchemaExample for WrittenContent {
    fn example() -> Self {
        Self::default()
    }
}

impl WCReference {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for WCReference {
    fn example() -> Self {
        Self::default()
    }
}

impl WCStyle {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for WCStyle {
    fn example() -> Self {
        Self::default()
    }
}