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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
use std::str::FromStr;

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum DatacapGroup {
    #[serde(rename = "da")]
    DA,
    #[serde(rename = "ldn-v3")]
    LDN,
    #[serde(rename = "e-fil")]
    EFIL,
}

impl FromStr for DatacapGroup {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "da" => Ok(Self::DA),
            "ldn-v3" => Ok(Self::LDN),
            "e-fil" => Ok(Self::EFIL),
            _ => Err(format!("{} is not a valid datacap group", s)),
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ApplicationFile {
    #[serde(rename = "Version")]
    pub version: u8,
    #[serde(rename = "ID")]
    pub id: String,
    #[serde(rename = "Issue Number")]
    pub issue_number: String,
    #[serde(rename = "Client")]
    pub client: Client,
    #[serde(rename = "Project")]
    pub project: Project,
    #[serde(rename = "Datacap")]
    pub datacap: Datacap,
    #[serde(rename = "Lifecycle")]
    pub lifecycle: LifeCycle,
    #[serde(rename = "Allocation Requests")]
    pub allocation: Allocations,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Client {
    #[serde(rename = "Name")]
    pub name: String,
    #[serde(rename = "Region")]
    pub region: String,
    #[serde(rename = "Industry")]
    pub industry: String,
    #[serde(rename = "Website")]
    pub website: String,
    #[serde(rename = "Social Media")]
    pub social_media: String,
    #[serde(rename = "Role")]
    pub role: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Datacap {
    #[serde(rename = "Type")]
    pub _group: DatacapGroup,
    #[serde(rename = "Data Type")]
    pub data_type: DataType,
    #[serde(rename = "Total Requested Amount")]
    pub total_requested_amount: String,
    #[serde(rename = "Single Size Dataset")]
    pub single_size_dataset: String,
    #[serde(rename = "Replicas")]
    pub replicas: u8,
    #[serde(rename = "Weekly Allocation")]
    pub weekly_allocation: String,
}

impl Default for Datacap {
    fn default() -> Self {
        Self {
            _group: DatacapGroup::LDN,
            data_type: DataType::Slingshot,
            total_requested_amount: "0".to_string(),
            single_size_dataset: "0".to_string(),
            replicas: 0,
            weekly_allocation: "0".to_string(),
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum DataType {
    #[serde(rename = "Slingshot")]
    Slingshot,
    #[serde(rename = "Public, Open Dataset (Research/Non-Profit)")]
    PublicOpenDatasetResearchNonProfit,
    #[serde(rename = "Public, Open Commercial/Enterprise")]
    PublicOpenCommercialEnterprise,
    #[serde(rename = "Private Commercial/Enterprise")]
    PrivateCommercialEnterprise,
    #[serde(rename = "Private Non-Profit / Social impact")]
    PrivateNonProfitSocialImpact,
}

impl FromStr for DataType {
    type Err = String;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Slingshot" => Ok(Self::Slingshot),
            "Public, Open Dataset (Research/Non-Profit)" => {
                Ok(Self::PublicOpenDatasetResearchNonProfit)
            }
            "Public, Open Commercial/Enterprise" => Ok(Self::PublicOpenCommercialEnterprise),
            "Private Commercial/Enterprise" => Ok(Self::PrivateCommercialEnterprise),
            "Private Non-Profit / Social impact" => Ok(Self::PrivateNonProfitSocialImpact),
            _ => Err(format!("{} is not a valid data type", s)),
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum AssociatedProjects {
    Yes(String),
    No,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum PublicDataset {
    Yes,
    No(String),
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum RetrivalFrequency {
    Daily,
    Weekly,
    Monthly,
    Yearly,
    Sporadic,
    Never,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageModularity {
    IPFS,
    Lotus,
    Singularity,
    Graphsplit,
    Other(String),
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageProviders {
    AWSCloud,
    GoogleCloud,
    AzureCloud,
    InternalStorage,
    Other(String),
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Project {
    #[serde(rename = "Project Id")]
    pub project_id: String,
    #[serde(rename = "Brief history of your project and organization")]
    pub history: String,
    #[serde(rename = "Is this project associated with other projects/ecosystem stakeholders?")]
    pub associated_projects: String,
    #[serde(rename = "Describe the data being stored onto Filecoin")]
    pub stored_data_desc: String,
    #[serde(rename = "Where was the data currently stored in this dataset sourced from} ")]
    pub previous_stoarge: String,
    #[serde(rename = "How do you plan to prepare the dataset")]
    pub dataset_prepare: String,
    #[serde(
        rename = "Please share a sample of the data (a link to a file, an image, a table, etc., are good ways to do this.)"
    )]
    pub data_sample_link: String,
    #[serde(
        rename = "Confirm that this is a public dataset that can be retrieved by anyone on the network (i.e., no specific permissions or access rights are required to view the data)"
    )]
    pub public_dataset: String,
    #[serde(rename = "What is the expected retrieval frequency for this data")]
    pub retrival_frequency: String,
    #[serde(rename = "For how long do you plan to keep this dataset stored on Filecoin")]
    pub dataset_life_span: String,
    #[serde(rename = "In which geographies do you plan on making storage deals")]
    pub geographis: String,
    #[serde(rename = "How will you be distributing your data to storage providers")]
    pub distribution: String,
    #[serde(
        rename = "Please list the provider IDs and location of the storage providers you will be working with. Note that it is a requirement to list a minimum of 5 unique provider IDs, and that your client address will be verified against this list in the future"
    )]
    pub providers: String,
    #[serde(
        rename = "Can you confirm that you will follow the Fil+ guideline (Data owner should engage at least 4 SPs and no single SP ID should receive >30% of a client's allocated DataCap)"
    )]
    pub filplus_guideline: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum DatasetLifeSpan {
    LessThanAYear,
    OneToOneAndHalfYears,
    OneAndHalfToTwoYears,
    TwoToThreeYears,
    MoreThanThreeYears,
    Permanently,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Provider {
    #[serde(rename = "ID")]
    pub id: String,
    #[serde(rename = "Location")]
    pub location: String,
    #[serde(rename = "SPOrg")]
    pub spo_org: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd)]
pub enum AppState {
    Submitted,
    ReadyToSign,
    StartSignDatacap,
    Granted,
    TotalDatacapReached,
    Error,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LifeCycle {
    #[serde(rename = "State")]
    pub state: AppState,
    #[serde(rename = "Validated At")]
    pub validated_at: String,
    #[serde(rename = "Validated By")]
    pub validated_by: String,
    #[serde(rename = "Active")]
    pub is_active: bool,
    #[serde(rename = "Updated At")]
    pub updated_at: String,
    #[serde(rename = "Active Request ID")]
    pub active_request: Option<String>,
    #[serde(rename = "On Chain Address")]
    pub client_on_chain_address: String,
    #[serde(rename = "Multisig Address")]
    pub multisig_address: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Allocations(pub Vec<Allocation>);

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub enum AllocationRequestType {
    First,
    Removal,
    Refill(u8),
}

impl ToString for AllocationRequestType {
    fn to_string(&self) -> String {
        match self {
            AllocationRequestType::First => "First".to_string(),
            AllocationRequestType::Removal => "Removal".to_string(),
            AllocationRequestType::Refill(_) => "Refill".to_string(),
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Allocation {
    #[serde(rename = "ID")]
    pub id: String,
    #[serde(rename = "Request Type")]
    pub request_type: String,
    #[serde(rename = "Created At")]
    pub created_at: String,
    #[serde(rename = "Updated At")]
    pub updated_at: String,
    #[serde(rename = "Active")]
    pub is_active: bool,
    #[serde(rename = "Allocation Amount")]
    pub amount: String,
    #[serde(rename = "Signers")]
    pub signers: Notaries,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Notaries(pub Vec<Notary>);

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NotaryInput {
    pub github_username: String,
    pub signing_address: String,
    pub created_at: String,
    pub message_cid: String,
}

impl From<NotaryInput> for Notary {
    fn from(input: NotaryInput) -> Self {
        Self {
            github_username: input.github_username,
            signing_address: input.signing_address,
            created_at: input.created_at,
            message_cid: input.message_cid,
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Notary {
    #[serde(rename = "Github Username")]
    pub github_username: String,
    #[serde(rename = "Signing Address")]
    pub signing_address: String,
    #[serde(rename = "Created At")]
    pub created_at: String,
    #[serde(rename = "Message CID")]
    pub message_cid: String,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct AllocationRequest {
    pub actor: String,
    pub id: String,
    pub kind: AllocationRequestType,
    pub is_active: bool,
    pub allocation_amount: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ValidNotaryList {
    notaries: Vec<String>,
}

impl ValidNotaryList {
    pub fn is_valid(&self, notary: &str) -> bool {
        self.notaries.contains(&notary.to_string())
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ValidRKHList {
    rkh: Vec<String>,
}

impl ValidRKHList {
    pub fn is_valid(&self, rkh: &str) -> bool {
        self.rkh.contains(&rkh.to_string())
    }
}