use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForwardSplit {
#[serde(default)]
pub id: Option<String>,
pub symbol: String,
pub cusip: String,
pub new_rate: f64,
pub old_rate: f64,
pub process_date: NaiveDate,
pub ex_date: NaiveDate,
#[serde(default)]
pub record_date: Option<NaiveDate>,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
#[serde(default)]
pub due_bill_redemption_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReverseSplit {
#[serde(default)]
pub id: Option<String>,
pub symbol: String,
pub old_cusip: String,
pub new_cusip: String,
pub new_rate: f64,
pub old_rate: f64,
pub process_date: NaiveDate,
pub ex_date: NaiveDate,
#[serde(default)]
pub record_date: Option<NaiveDate>,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct UnitSplit {
#[serde(default)]
pub id: Option<String>,
pub old_symbol: String,
pub old_cusip: String,
pub old_rate: f64,
pub new_symbol: String,
pub new_cusip: String,
pub new_rate: f64,
pub alternate_symbol: String,
pub alternate_cusip: String,
pub alternate_rate: f64,
pub process_date: NaiveDate,
pub effective_date: NaiveDate,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct StockDividend {
#[serde(default)]
pub id: Option<String>,
pub symbol: String,
pub cusip: String,
pub rate: f64,
pub process_date: NaiveDate,
pub ex_date: NaiveDate,
#[serde(default)]
pub record_date: Option<NaiveDate>,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CashDividend {
#[serde(default)]
pub id: Option<String>,
pub symbol: String,
pub cusip: String,
pub rate: f64,
pub special: bool,
pub foreign: bool,
pub process_date: NaiveDate,
pub ex_date: NaiveDate,
#[serde(default)]
pub record_date: Option<NaiveDate>,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
#[serde(default)]
pub due_bill_on_date: Option<NaiveDate>,
#[serde(default)]
pub due_bill_off_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SpinOff {
#[serde(default)]
pub id: Option<String>,
pub source_symbol: String,
pub source_cusip: String,
pub source_rate: f64,
pub new_symbol: String,
pub new_cusip: String,
pub new_rate: f64,
pub process_date: NaiveDate,
pub ex_date: NaiveDate,
#[serde(default)]
pub record_date: Option<NaiveDate>,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
#[serde(default)]
pub due_bill_redemption_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CashMerger {
#[serde(default)]
pub id: Option<String>,
#[serde(default)]
pub acquirer_symbol: Option<String>,
#[serde(default)]
pub acquirer_cusip: Option<String>,
pub acquiree_symbol: String,
pub acquiree_cusip: String,
pub rate: f64,
pub process_date: NaiveDate,
pub effective_date: NaiveDate,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct StockMerger {
#[serde(default)]
pub id: Option<String>,
pub acquirer_symbol: String,
pub acquirer_cusip: String,
pub acquirer_rate: f64,
pub acquiree_symbol: String,
pub acquiree_cusip: String,
pub acquiree_rate: f64,
pub process_date: NaiveDate,
pub effective_date: NaiveDate,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct StockAndCashMerger {
#[serde(default)]
pub id: Option<String>,
pub acquirer_symbol: String,
pub acquirer_cusip: String,
pub acquirer_rate: f64,
pub acquiree_symbol: String,
pub acquiree_cusip: String,
pub acquiree_rate: f64,
pub cash_rate: f64,
pub process_date: NaiveDate,
pub effective_date: NaiveDate,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Redemption {
#[serde(default)]
pub id: Option<String>,
pub symbol: String,
pub cusip: String,
pub rate: f64,
pub process_date: NaiveDate,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct NameChange {
#[serde(default)]
pub id: Option<String>,
pub old_symbol: String,
pub old_cusip: String,
pub new_symbol: String,
pub new_cusip: String,
pub process_date: NaiveDate,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WorthlessRemoval {
#[serde(default)]
pub id: Option<String>,
pub symbol: String,
pub cusip: String,
pub process_date: NaiveDate,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct RightsDistribution {
#[serde(default)]
pub id: Option<String>,
pub source_symbol: String,
pub source_cusip: String,
pub new_symbol: String,
pub new_cusip: String,
pub rate: f64,
pub process_date: NaiveDate,
pub ex_date: NaiveDate,
#[serde(default)]
pub payable_date: Option<NaiveDate>,
#[serde(default)]
pub record_date: Option<NaiveDate>,
#[serde(default)]
pub expiration_date: Option<NaiveDate>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CorporateActions {
#[serde(default)]
pub forward_splits: Vec<ForwardSplit>,
#[serde(default)]
pub reverse_splits: Vec<ReverseSplit>,
#[serde(default)]
pub unit_splits: Vec<UnitSplit>,
#[serde(default)]
pub stock_dividends: Vec<StockDividend>,
#[serde(default)]
pub cash_dividends: Vec<CashDividend>,
#[serde(default)]
pub spin_offs: Vec<SpinOff>,
#[serde(default)]
pub cash_mergers: Vec<CashMerger>,
#[serde(default)]
pub stock_mergers: Vec<StockMerger>,
#[serde(default)]
pub stock_and_cash_mergers: Vec<StockAndCashMerger>,
#[serde(default)]
pub redemptions: Vec<Redemption>,
#[serde(default)]
pub name_changes: Vec<NameChange>,
#[serde(default)]
pub worthless_removals: Vec<WorthlessRemoval>,
#[serde(default)]
pub rights_distributions: Vec<RightsDistribution>,
}
impl CorporateActions {
#[must_use]
pub fn len(&self) -> usize {
self.forward_splits.len()
+ self.reverse_splits.len()
+ self.unit_splits.len()
+ self.stock_dividends.len()
+ self.cash_dividends.len()
+ self.spin_offs.len()
+ self.cash_mergers.len()
+ self.stock_mergers.len()
+ self.stock_and_cash_mergers.len()
+ self.redemptions.len()
+ self.name_changes.len()
+ self.worthless_removals.len()
+ self.rights_distributions.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}