use parlov_core::{ProbeDefinition, Technique};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ChainProvenance {
pub producer_kind: String,
pub producer_value: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum RiskLevel {
Safe,
MethodDestructive,
OperationDestructive,
}
#[derive(Debug, Clone)]
pub struct StrategyMetadata {
pub strategy_id: &'static str,
pub strategy_name: &'static str,
pub risk: RiskLevel,
}
#[derive(Debug, Clone)]
pub struct ProbePair {
pub baseline: ProbeDefinition,
pub probe: ProbeDefinition,
pub canonical_baseline: Option<ProbeDefinition>,
pub metadata: StrategyMetadata,
pub technique: Technique,
pub chain_provenance: Option<ChainProvenance>,
}
#[derive(Debug, Clone)]
pub struct BurstSpec {
pub baseline: ProbeDefinition,
pub probe: ProbeDefinition,
pub burst_count: usize,
pub metadata: StrategyMetadata,
pub technique: Technique,
pub chain_provenance: Option<ChainProvenance>,
}
#[derive(Debug, Clone)]
pub enum ProbeSpec {
Pair(ProbePair),
Burst(BurstSpec),
HeaderDiff(ProbePair),
}
impl ProbeSpec {
#[must_use]
pub fn technique(&self) -> &Technique {
match self {
Self::Pair(p) | Self::HeaderDiff(p) => &p.technique,
Self::Burst(b) => &b.technique,
}
}
#[must_use]
pub fn chain_provenance(&self) -> Option<&ChainProvenance> {
match self {
Self::Pair(p) | Self::HeaderDiff(p) => p.chain_provenance.as_ref(),
Self::Burst(b) => b.chain_provenance.as_ref(),
}
}
#[must_use]
pub fn with_chain_provenance(self, prov: ChainProvenance) -> Self {
match self {
Self::Pair(mut p) => {
p.chain_provenance = Some(prov);
Self::Pair(p)
}
Self::HeaderDiff(mut p) => {
p.chain_provenance = Some(prov);
Self::HeaderDiff(p)
}
Self::Burst(mut b) => {
b.chain_provenance = Some(prov);
Self::Burst(b)
}
}
}
}
#[cfg(test)]
#[path = "types_tests.rs"]
mod tests;