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
use crate::utils::messaging::MaybeRequest;
use derive::FromValue;
use netidx_derive::Pack;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Clone, Copy, Pack, FromValue, Serialize, Deserialize)]
pub enum OrderAuthorityMessage {
    RequestAllocation(Uuid, u64),
    Allocation(Uuid, Option<OrderIdAllocation>),
}

#[derive(Debug, Clone, Copy, Pack, FromValue, Serialize, Deserialize)]
pub struct OrderIdAllocation {
    pub allocation_min: u64,
    pub allocation_max: u64,
}

impl MaybeRequest for OrderAuthorityMessage {
    fn request_id(&self) -> Option<Uuid> {
        match self {
            OrderAuthorityMessage::RequestAllocation(uuid, _) => Some(*uuid),
            OrderAuthorityMessage::Allocation(..) => None,
        }
    }

    fn response_id(&self) -> Option<Uuid> {
        match self {
            OrderAuthorityMessage::RequestAllocation(..) => None,
            OrderAuthorityMessage::Allocation(uuid, _) => Some(*uuid),
        }
    }
}