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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
use serde::{Deserialize, Serialize};

use crate::{
    game_mechanics::{skills::SkillId, specializations::SpecializationId, traits::TraitId},
    items::{itemstats::StatsId, recipes::RecipeId, skins::SkinId, ItemId},
    misc::{colors::ColorId, titles::TitleId},
    pvp::amulets::AmuletId,
    wvw::abilities::AbilityId,
    BulkEndpoint, Endpoint, EndpointWithId, TimeStamp,
};

pub type Age = u64;
pub type CharacterId = String;
pub type BackStoryId = String;

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Backstory {
    pub backstory: Vec<BackStoryId>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Race {
    Asura,
    Charr,
    Human,
    Norn,
    Sylvari,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Gender {
    Male,
    Female,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Profession {
    Elementalist,
    Engineer,
    Guardian,
    Mesmer,
    Necromancer,
    Ranger,
    Revenant,
    Thief,
    Warrior,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Core {
    pub name: CharacterId,
    pub race: Race,
    pub gender: Gender,
    pub profession: Profession,
    pub level: u8,
    pub guild: Option<String>,
    pub age: Age,
    pub created: TimeStamp,
    pub last_modified: TimeStamp,
    pub deaths: u32,
    pub title: Option<TitleId>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Discipline {
    Armorsmith,
    Artificer,
    Chef,
    Huntsman,
    Jeweler,
    Leatherworker,
    Scribe,
    Tailor,
    Weaponsmith,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Craft {
    pub discipline: Discipline,
    pub rating: u16,
    pub active: bool,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Crafting {
    pub crafting: Vec<Craft>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Slot {
    HelmAquatic,
    Backpack,
    Coat,
    Boots,
    Gloves,
    Helm,
    Leggings,
    Shoulders,
    Accessory1,
    Accessory2,
    Ring1,
    Ring2,
    Amulet,
    WeaponAquaticA,
    WeaponAquaticB,
    WeaponA1,
    WeaponA2,
    WeaponB1,
    WeaponB2,
    Sickle,
    Axe,
    Pick,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
#[serde(deny_unknown_fields)]
pub struct Attributes {
    pub power: Option<u16>,
    pub precision: Option<u16>,
    pub crit_damage: Option<u16>,
    pub toughness: Option<u16>,
    pub vitality: Option<u16>,
    pub condition_damage: Option<u16>,
    pub condition_duration: Option<u16>,
    pub healing: Option<u16>,
    pub boon_duration: Option<u16>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Stats {
    pub id: StatsId,
    pub attributes: Attributes,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Binding {
    Character,
    Account,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Location {
    Equipped,
    Armory,
    EquippedFromLegendaryArmory,
    LegendaryArmory,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Equip {
    pub id: ItemId,
    pub slot: Option<Slot>,
    /// only present in character.equipment
    pub count: Option<usize>,
    pub infusions: Option<Vec<ItemId>>,
    pub upgrades: Option<Vec<ItemId>>,
    pub skin: Option<SkinId>,
    pub stats: Option<Stats>,
    pub binding: Option<Binding>,
    pub location: Location,
    pub charges: Option<u16>,
    pub bound_to: Option<String>,
    pub dyes: Option<Vec<Option<ColorId>>>,
    /// only present in character.equipment
    pub tabs: Option<Vec<usize>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Equipment {
    pub equipment: Vec<Equip>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct InventoryItem {
    pub id: ItemId,
    pub count: u8,
    pub charges: Option<u8>,
    pub infusions: Option<Vec<ItemId>>,
    pub upgrades: Option<Vec<ItemId>>,
    pub upgrade_slot_indices: Option<Vec<usize>>,
    pub skin: Option<SkinId>,
    pub stats: Option<Stats>,
    pub binding: Option<Binding>,
    pub bound_to: Option<String>,
    pub dyes: Option<Vec<ColorId>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct InventoryBag {
    pub id: ItemId,
    pub size: u8,
    pub inventory: Vec<Option<InventoryItem>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Inventory {
    pub bags: Vec<Option<InventoryBag>>,
}

pub type Utilities = [Option<SkillId>; 3];

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Skillset {
    pub heal: Option<SkillId>,
    pub utilities: Utilities,
    pub elite: Option<SkillId>,
    // TODO: legends enum
    pub legends: Option<Vec<String>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SkillDataSet {
    pub pve: Skillset,
    pub pvp: Skillset,
    pub wvw: Skillset,
}

pub type TraitSet = [Option<TraitId>; 3];

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TraitLine {
    pub id: Option<SpecializationId>,
    pub traits: Option<TraitSet>,
}

pub type Specialization = [Option<TraitLine>; 3];

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SpecializationSet {
    pub pve: Specialization,
    pub pvp: Specialization,
    pub wvw: Specialization,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TrainingSet {
    // TODO: training id
    pub id: u64,
    pub spent: u16,
    pub done: bool,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Training {
    pub training: Vec<TrainingSet>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Recipes {
    pub recipes: Vec<RecipeId>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct WvwAbility {
    pub id: AbilityId,
    pub rank: u8,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EquipmentPvp {
    pub amulet: Option<AmuletId>,
    pub rune: Option<ItemId>,
    pub sigils: (
        Option<ItemId>,
        Option<ItemId>,
        Option<ItemId>,
        Option<ItemId>,
    ),
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Flags {
    Beta,
}

pub type PetId = u16;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct BuildPets {
    pub terrestrial: [Option<PetId>; 2],
    pub aquatic: [Option<PetId>; 2],
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BuildLegends {
    pub legends: LegendSlots,
    pub aquatic_legends: LegendSlots,
}

pub type LegendId = String;
pub type LegendSlots = [Option<LegendId>; 2];

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BuildTemplate {
    pub name: Option<String>,
    pub profession: Option<Profession>,
    pub specializations: [TraitLine; 3],
    pub skills: Skillset,
    pub aquatic_skills: Skillset,
    pub pets: Option<BuildPets>,
    pub legends: Option<LegendSlots>,
    pub aquatic_legends: Option<LegendSlots>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BuildTab {
    /// this index starts at 1
    pub tab: usize,
    pub is_active: bool,
    pub build: BuildTemplate,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EquipmentTab {
    /// this index starts at 1
    pub tab: usize,
    pub name: String,
    pub is_active: bool,
    pub equipment: Vec<Equip>,
    pub equipment_pvp: Option<EquipmentPvp>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Character {
    pub backstory: Vec<BackStoryId>,
    #[serde(flatten)]
    pub core: Core,
    pub crafting: Vec<Craft>,
    #[serde(default)]
    pub equipment: Vec<Equip>,
    #[serde(default)]
    pub bags: Vec<Option<InventoryBag>>,
    #[serde(default)]
    pub recipes: Vec<RecipeId>,
    #[serde(default)]
    pub training: Vec<TrainingSet>,
    #[serde(default)]
    pub build_tabs: Vec<BuildTab>,
    pub build_tabs_unlocked: Option<usize>,
    pub active_build_tab: Option<usize>,
    #[serde(default)]
    pub equipment_tabs: Vec<EquipmentTab>,
    pub equipment_tabs_unlocked: Option<usize>,
    pub active_equipment_tab: Option<usize>,
    #[serde(default)]
    pub wvw_abilities: Vec<WvwAbility>,
    pub flags: Vec<Flags>,
}

impl EndpointWithId for Character {
    type IdType = CharacterId;
}

impl Endpoint for Character {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}

impl BulkEndpoint for Character {
    const ALL: bool = true;

    fn id(&self) -> &Self::IdType {
        &self.core.name
    }
}

impl EndpointWithId for Core {
    type IdType = CharacterId;

    fn format_url(id: &str) -> String {
        format!("{}/{}/core", Self::URL, id)
    }
}

impl Endpoint for Core {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}

impl EndpointWithId for Backstory {
    type IdType = CharacterId;

    fn format_url(id: &str) -> String {
        format!("{}/{}/backstory", Self::URL, id)
    }
}

impl Endpoint for Backstory {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}

impl EndpointWithId for Crafting {
    type IdType = CharacterId;

    fn format_url(id: &str) -> String {
        format!("{}/{}/crafting", Self::URL, id)
    }
}

impl Endpoint for Crafting {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}

impl EndpointWithId for Equipment {
    type IdType = CharacterId;

    fn format_url(id: &str) -> String {
        format!("{}/{}/equipment", Self::URL, id)
    }
}

impl Endpoint for Equipment {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}

impl EndpointWithId for Inventory {
    type IdType = CharacterId;

    fn format_url(id: &str) -> String {
        format!("{}/{}/inventory", Self::URL, id)
    }
}

impl Endpoint for Inventory {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}

impl EndpointWithId for Recipes {
    type IdType = CharacterId;

    fn format_url(id: &str) -> String {
        format!("{}/{}/recipes", Self::URL, id)
    }
}

impl Endpoint for Recipes {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}

impl EndpointWithId for Training {
    type IdType = CharacterId;

    fn format_url(id: &str) -> String {
        format!("{}/{}/training", Self::URL, id)
    }
}

impl Endpoint for Training {
    const AUTHENTICATED: bool = true;
    const LOCALE: bool = false;
    const URL: &'static str = "v2/characters";
    const VERSION: &'static str = "2022-06-14T00:00:00.000Z";
}