aboutsummaryrefslogtreecommitdiff
path: root/karlcommon/src/lib.rs
blob: 809a036d9ac06984a93429a1f5b47c68d06ebdc4 (plain)
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
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum ClientboundPacket {
    Handshake { version: String },
    Error(String),
    DownloadResponse(Vec<Task>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum ServerboundPacket {
    Download,
    UpdateTask(Task),
    RemoveTask(u64),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Task {
    pub id: u64,
    pub name: String,
    pub description: String,

    pub tags: Vec<String>,
    pub priority: f64,

    pub completed: Option<u64>,
    pub scheduled: Option<u64>,

    pub occurence: Option<Condition>,
    pub deadline: Option<Condition>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Condition {
    From(Box<Condition>),

    Or(Vec<Condition>),
    And(Vec<Condition>),
    Invert(Box<Condition>),

    Equal {
        prop: Property,
        value: i64,
        modulus: Option<i64>,
    },
    Range {
        prop: Property,
        min: i64,
        max: i64,
        modulus: Option<i64>,
    },
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Property {
    Year,
    Monthofyear,
    Weekofmonth,
    Dayofyear,
    Dayofmonth,
    Dayofweek,
    Hour,
    Minute,
    Second,
    Unix,
}