wb_cache/test/simulation/scriptwriter/
steps.rs

1use serde::Deserialize;
2use serde::Serialize;
3use strum::Display;
4
5use crate::test::simulation::db::entity::Customer as DbCustomer;
6use crate::test::simulation::db::entity::InventoryRecord as DbInventoryRecord;
7use crate::test::simulation::db::entity::Order as DbOrder;
8use crate::test::simulation::db::entity::Product as DbProduct;
9use crate::test::simulation::db::entity::Session as DbSession;
10
11use super::entity::inventory::IncomingShipment;
12use super::entity::inventory::InventoryCheck;
13
14#[derive(Clone, Debug, Serialize, Deserialize)]
15pub struct ScriptTitle {
16    pub period:          i32,
17    pub products:        i32,
18    pub market_capacity: u32,
19}
20
21#[derive(Display, Clone, Debug, Serialize, Deserialize)]
22#[serde(deny_unknown_fields)]
23pub enum Step {
24    /// Initial header for the script with the introductory information.
25    #[serde(rename = "h")]
26    Title(ScriptTitle),
27    #[serde(rename = "d")]
28    /// The simulation day number.
29    Day(i32),
30    /// Add a new product into the database.
31    // #[serde(rename = "ap")]
32    AddProduct(DbProduct),
33    /// Register a new customer
34    #[serde(rename = "ac")]
35    AddCustomer(DbCustomer),
36    /// A new purchase order from customer
37    #[serde(rename = "ao")]
38    AddOrder(DbOrder),
39    #[serde(rename = "uo")]
40    UpdateOrder(DbOrder),
41    /// Add a new session entry.
42    #[serde(rename = "as")]
43    AddSession(DbSession),
44    /// Update an existing session entry.
45    UpdateSession(DbSession),
46    /// Collect expired sessions.
47    CollectSessions,
48    /// Update an existing order status.
49    /// Add a new inventory record.
50    #[serde(rename = "ai")]
51    AddInventoryRecord(DbInventoryRecord),
52    /// Update an existing inventory record.
53    #[serde(rename = "is")]
54    AddStock(IncomingShipment),
55    /// Increase product views counter.
56    ViewProduct(i32),
57    /// Check the inventory stock and make sure it corresponds to the expected value.
58    /// This is useful for testing purposes to ensure that scenario is in sync with the simulation.
59    #[serde(rename = "ci")]
60    CheckInventory(InventoryCheck),
61}