fts_core/models/product.rs
1use crate::models::ProductId;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use utoipa::{IntoParams, ToSchema};
5
6/// A product record combines a standard product ID with implementation-specific data.
7///
8/// Products are the fundamental tradable entities in the system. The core only defines
9/// products by their ID, allowing implementations to attach domain-specific data.
10///
11/// Product records are immutable once defined.
12#[derive(Serialize, Deserialize, ToSchema)]
13pub struct ProductRecord<T> {
14 /// Unique identifier for the product
15 pub id: ProductId,
16 /// Additional product-specific data defined by the implementation
17 #[serde(flatten)]
18 pub data: T,
19}
20
21/// Standard response format for product queries.
22///
23/// This structure provides a consistent format for returning product query results,
24/// including optional pagination metadata.
25#[derive(Serialize, ToSchema)]
26pub struct ProductQueryResponse<T, U> {
27 /// Collection of product query results
28 pub results: Vec<T>,
29 /// Optional pagination information for retrieving additional results
30 #[serde(skip_serializing_if = "Option::is_none")]
31 pub more: Option<U>,
32}
33
34/// A description of a product in a forward market
35#[derive(Debug, PartialEq, Serialize, Deserialize, ToSchema)]
36pub struct ProductData {
37 /// A tag describing the type of product (e.g. "FORWARD" or "OPTION")
38 pub kind: String,
39 /// The starting time of the delivery interval for the product
40 #[serde(with = "time::serde::rfc3339")]
41 pub from: OffsetDateTime,
42 /// The stopping time of the delivery interval for the product
43 #[serde(with = "time::serde::rfc3339")]
44 pub thru: OffsetDateTime,
45}
46
47/// A query for searching for known products
48#[derive(Debug, Serialize, Deserialize, IntoParams, ToSchema)]
49#[into_params(parameter_in = Query)]
50pub struct ProductQuery {
51 /// An optional filter to restrict the kind of product by
52 pub kind: Option<String>,
53 /// An optional filter to select products with delivery windows on or before this value
54 #[serde(with = "time::serde::rfc3339::option")]
55 pub before: Option<OffsetDateTime>,
56 /// An optional filter to select products with delivery windows on or after this value
57 #[serde(with = "time::serde::rfc3339::option")]
58 pub after: Option<OffsetDateTime>,
59}