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
use crate::owl::{Annotation, Axiom, ClassConstructor};

/// Defines that the subject is a sub class of the object.
///
/// Structure `(subject, object, annotations)`.
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct SubClassOf {
    #[serde(rename = "cls")]
    pub cls: Box<ClassConstructor>,
    #[serde(rename = "parentClass")]
    pub parent_class: Box<ClassConstructor>,
    #[serde(rename = "annotations")]
    pub annotations: Vec<Annotation>,
}

impl SubClassOf {
    pub fn new(
        cls: Box<ClassConstructor>,
        parent_class: Box<ClassConstructor>,
        annotations: Vec<Annotation>,
    ) -> Self {
        Self {
            cls,
            parent_class,
            annotations,
        }
    }
}

impl From<SubClassOf> for Box<ClassConstructor> {
    fn from(sco: SubClassOf) -> Self {
        Box::new(ClassConstructor::SubClassOf(sco))
    }
}
impl From<SubClassOf> for ClassConstructor {
    fn from(sco: SubClassOf) -> Self {
        ClassConstructor::SubClassOf(sco)
    }
}

impl ClassConstructor {
    pub fn sub_class_of(&self) -> Option<&SubClassOf> {
        match self {
            ClassConstructor::SubClassOf(s) => Some(s),
            _ => None,
        }
    }
}

impl From<SubClassOf> for Axiom {
    fn from(sco: SubClassOf) -> Self {
        Axiom::SubClassOf(sco)
    }
}

#[cfg(feature = "wasm")]
mod wasm {
    use wasm_bindgen::prelude::wasm_bindgen;
    #[wasm_bindgen(typescript_custom_section)]
    const WASM_API: &'static str = r#"
export type SubClassOf = {
    cls: ClassConstructor,
    parentClass: ClassConstructor,
    annotations: Array<Annotation>,
};
"#;
}