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
use crate::model::*;

#[derive(Debug)]
pub struct Collection<D>
where
    D: DocReference,
{
    pub(crate) collection_class: ClassDeclarationHandle,
    pub(crate) item_type: FunctionArgument,
    pub(crate) create_func: Handle<Function<D>>,
    pub(crate) delete_func: Handle<Function<D>>,
    pub(crate) add_func: Handle<Function<D>>,
    pub(crate) has_reserve: bool,
}

impl<D> Collection<D>
where
    D: DocReference,
{
    pub(crate) fn new(
        collection_class: ClassDeclarationHandle,
        item_type: FunctionArgument,
        create_func: Handle<Function<D>>,
        delete_func: Handle<Function<D>>,
        add_func: Handle<Function<D>>,
        has_reserve: bool,
    ) -> Collection<D> {
        Collection {
            collection_class,
            item_type,
            create_func,
            delete_func,
            add_func,
            has_reserve,
        }
    }

    pub fn name(&self) -> &Name {
        &self.collection_class.name
    }
}

impl Collection<Unvalidated> {
    pub(crate) fn validate(
        &self,
        lib: &LibraryFields,
    ) -> BindResult<Handle<Collection<Validated>>> {
        Ok(Handle::new(Collection {
            collection_class: self.collection_class.clone(),
            item_type: self.item_type.clone(),
            create_func: self.create_func.validate(lib)?,
            delete_func: self.delete_func.validate(lib)?,
            add_func: self.add_func.validate(lib)?,
            has_reserve: self.has_reserve,
        }))
    }
}

pub type CollectionHandle = Handle<Collection<Unvalidated>>;