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
pub mod site_kit;

use crate::pages::PageId;
use shaku::{module, Interface, Provider};

pub trait SiteRepository: Interface {
    fn create(&mut self, site: Box<dyn Site>) -> Box<dyn SiteId>;
    fn read(&self, read_by: SiteReadOption) -> (&Box<dyn Site>, Box<dyn SiteId>);
    fn delete(&self, site_id: Box<dyn Site>) -> bool;
}

pub trait CreatedSite {
    fn site(&self) -> dyn Site;
    fn site_id(&self) -> Box<dyn SiteId>;
}

pub trait SiteIdBuilder {
    fn build(&self, id: u8) -> Box<dyn SiteId>;
}

#[derive(Provider)]
#[shaku(interface = SiteIdBuilder)]
pub struct SiteIdBuilderImpl;

impl SiteIdBuilder for SiteIdBuilderImpl {
    fn build(&self, id: u8) -> Box<dyn SiteId> {
        let result = SiteIdImpl { value: id };
        let b: Box<dyn SiteId> = Box::new(result);
        b
    }
}

pub trait SiteBuilder: Interface {
    fn build(&self) -> Box<dyn Site>;
}

#[derive(Provider)]
#[shaku(interface = SiteBuilder)]
pub struct SiteBuilderImpl;

impl SiteBuilder for SiteBuilderImpl {
    fn build(&self) -> Box<dyn Site> {
        let site = SiteImpl { domain: "domain.com".to_string(), name: "".to_string() };
        let result: Box<dyn Site> = Box::new(site);
        result
    }
}

pub enum SiteReadOption {
    SiteId(Box<dyn SiteId>),
    Domain(String),
}

pub trait Site: Interface {
    fn domain(&self) -> String;
}

struct SiteImpl {
    domain: String,
    name: String,
}

impl Site for SiteImpl {
    fn domain(&self) -> String {
        self.domain.clone()
    }
}

pub trait SiteId {
    fn value(&self) -> u8;
}

struct SiteIdImpl {
    value: u8,
}

impl SiteId for SiteIdImpl {
    fn value(&self) -> u8 {
        self.value
    }
}

pub struct SitePages {
    pages: Vec<PageId>,
}

module! {
    SiteModule {
        components = [],
        providers = [SiteIdBuilderImpl]
    }
}