wip
This commit is contained in:
56
src/objects/grid4/reservation.rs
Normal file
56
src/objects/grid4/reservation.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use crate::store::BaseData;
|
||||
use rhai::{CustomType, TypeBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Reservation status as per V spec
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
||||
pub enum ReservationStatus {
|
||||
#[default]
|
||||
Pending,
|
||||
Confirmed,
|
||||
Assigned,
|
||||
Cancelled,
|
||||
Done,
|
||||
}
|
||||
|
||||
/// Grid4 Reservation model
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, crate::DeriveObject)]
|
||||
pub struct Reservation {
|
||||
pub base_data: BaseData,
|
||||
/// links back to customer for this capacity
|
||||
#[index]
|
||||
pub customer_id: u32,
|
||||
pub compute_slices: Vec<u32>,
|
||||
pub storage_slices: Vec<u32>,
|
||||
pub status: ReservationStatus,
|
||||
/// if obligation then will be charged and money needs to be in escrow, otherwise its an intent
|
||||
pub obligation: bool,
|
||||
/// epoch
|
||||
pub start_date: u32,
|
||||
pub end_date: u32,
|
||||
}
|
||||
|
||||
impl Reservation {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
base_data: BaseData::new(),
|
||||
customer_id: 0,
|
||||
compute_slices: Vec::new(),
|
||||
storage_slices: Vec::new(),
|
||||
status: ReservationStatus::Pending,
|
||||
obligation: false,
|
||||
start_date: 0,
|
||||
end_date: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn customer_id(mut self, v: u32) -> Self { self.customer_id = v; self }
|
||||
pub fn add_compute_slice(mut self, id: u32) -> Self { self.compute_slices.push(id); self }
|
||||
pub fn compute_slices(mut self, v: Vec<u32>) -> Self { self.compute_slices = v; self }
|
||||
pub fn add_storage_slice(mut self, id: u32) -> Self { self.storage_slices.push(id); self }
|
||||
pub fn storage_slices(mut self, v: Vec<u32>) -> Self { self.storage_slices = v; self }
|
||||
pub fn status(mut self, v: ReservationStatus) -> Self { self.status = v; self }
|
||||
pub fn obligation(mut self, v: bool) -> Self { self.obligation = v; self }
|
||||
pub fn start_date(mut self, v: u32) -> Self { self.start_date = v; self }
|
||||
pub fn end_date(mut self, v: u32) -> Self { self.end_date = v; self }
|
||||
}
|
||||
Reference in New Issue
Block a user