use rust_decimal::Decimal;
use rust_decimal::serde::float_option as decimal_opt;
use serde::Deserialize;
use crate::error::{Error, Result};
pub mod equity;
pub mod option;
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct Content {
pub key: String,
pub delayed: bool,
#[serde(default)]
pub symbol: Option<String>,
#[serde(default)]
pub timestamp: Option<u64>,
#[serde(default)]
pub sort_field: Option<String>,
#[serde(default)]
pub frequency: Option<i32>,
#[serde(default)]
pub items: Vec<Item>,
}
#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq, Hash)]
#[serde(default, rename_all = "camelCase")]
#[non_exhaustive]
pub struct Item {
pub description: Option<String>,
#[serde(with = "decimal_opt")]
pub last_price: Option<Decimal>,
#[serde(with = "decimal_opt")]
pub market_share: Option<Decimal>,
#[serde(with = "decimal_opt")]
pub net_change: Option<Decimal>,
#[serde(with = "decimal_opt")]
pub net_percent_change: Option<Decimal>,
pub symbol: Option<String>,
pub total_volume: Option<u64>,
pub trades: Option<i64>,
pub volume: Option<u64>,
}
pub(crate) fn decode_batch(
remapped: serde_json::Value,
service_label: &str,
) -> Result<Vec<Content>> {
serde_json::from_value(remapped).map_err(|e| Error::Codec {
context: format!("{service_label} content"),
reason: e.to_string(),
})
}