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
use std::collections::HashMap;
use vit_servicing_station_lib::db::models::community_advisors_reviews::AdvisorReview;
use vit_servicing_station_lib::db::models::goals::Goal;
use vit_servicing_station_lib::db::models::groups::Group;
use vit_servicing_station_lib::db::models::proposals::FullProposalInfo;
use vit_servicing_station_lib::db::models::{
    api_tokens::ApiTokenData, challenges::Challenge, funds::Fund, voteplans::Voteplan,
};

#[derive(Debug, Clone)]
pub struct Snapshot {
    funds: Vec<Fund>,
    proposals: Vec<FullProposalInfo>,
    challenges: Vec<Challenge>,
    tokens: HashMap<String, ApiTokenData>,
    voteplans: Vec<Voteplan>,
    reviews: Vec<AdvisorReview>,
    goals: Vec<Goal>,
}

impl Snapshot {
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        funds: Vec<Fund>,
        proposals: Vec<FullProposalInfo>,
        challenges: Vec<Challenge>,
        tokens: HashMap<String, ApiTokenData>,
        voteplans: Vec<Voteplan>,
        reviews: Vec<AdvisorReview>,
        goals: Vec<Goal>,
    ) -> Self {
        Self {
            funds,
            proposals,
            challenges,
            tokens,
            voteplans,
            reviews,
            goals,
        }
    }

    pub fn funds(&self) -> Vec<Fund> {
        self.funds.clone()
    }

    pub fn proposals(&self) -> Vec<FullProposalInfo> {
        self.proposals.clone()
    }

    pub fn tokens(&self) -> HashMap<String, ApiTokenData> {
        self.tokens.clone()
    }

    pub fn voteplans(&self) -> Vec<Voteplan> {
        self.voteplans.clone()
    }

    pub fn funds_mut(&mut self) -> &mut Vec<Fund> {
        &mut self.funds
    }

    pub fn proposals_mut(&mut self) -> &mut Vec<FullProposalInfo> {
        &mut self.proposals
    }

    pub fn voteplans_mut(&mut self) -> &mut Vec<Voteplan> {
        &mut self.voteplans
    }

    pub fn proposal_by_id(&self, id: &str) -> Option<&FullProposalInfo> {
        self.proposals
            .iter()
            .find(|x| x.proposal.proposal_id.eq(id))
    }

    pub fn fund_by_id(&self, id: i32) -> Option<&Fund> {
        self.funds.iter().find(|x| x.id == id)
    }

    pub fn any_token(&self) -> (String, ApiTokenData) {
        let (hash, token) = self.tokens.iter().next().unwrap();
        (hash.to_string(), token.clone())
    }

    pub fn token_hash(&self) -> String {
        self.any_token().0
    }

    pub fn challenges(&self) -> Vec<Challenge> {
        self.challenges.clone()
    }

    pub fn challenges_mut(&mut self) -> &mut Vec<Challenge> {
        &mut self.challenges
    }

    pub fn advisor_reviews(&self) -> Vec<AdvisorReview> {
        self.reviews.clone()
    }

    pub fn groups(&self) -> Vec<Group> {
        self.funds
            .iter()
            .flat_map(|f| f.groups.iter())
            .cloned()
            .collect()
    }

    pub fn advisor_reviews_mut(&mut self) -> &mut Vec<AdvisorReview> {
        &mut self.reviews
    }

    pub fn goals(&self) -> Vec<Goal> {
        self.goals.clone()
    }
}