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
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use self::attack::Attack;

pub mod attack;

#[cfg_attr(feature = "diesel", derive(Queryable, Insertable))]
#[cfg_attr(feature = "diesel", diesel(table_name = "actions"))]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub struct Action {
    pub id: String,
    pub action: ActionType,
}

impl Action {
    pub fn new(action: ActionType) -> Self {
        Self {
            id: Uuid::new_v4().to_string(),
            action,
        }
    }
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub enum ActionType {
    Attack(Attack),
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ActionRequest {
    pub action: Option<ActionType>,
}

impl ActionRequest {
    pub fn to_action(&self) -> Option<Action> {
        match &self.action {
            Some(action) => Some(Action::new(action.clone())),
            None => None,
        }
    }
}