use chrono::NaiveDate;
use super::{RepairabilityRuleset, RepairabilityThresholds, RepairabilityWeights};
use crate::error::CalcError;
use crate::repairability::parameters::RepairabilityInputs;
use crate::ruleset::{EffectiveDateBound, RegulatoryBasis, Ruleset, RulesetId, RulesetVersion};
static SMARTPHONE_WEIGHTS: RepairabilityWeights = RepairabilityWeights {
disassembly: 0.25,
spare_parts: 0.15,
repair_info: 0.15,
diagnostic_tools: 0.15,
software_updatability: 0.15,
customer_support: 0.15,
};
static SMARTPHONE_THRESHOLDS: RepairabilityThresholds = RepairabilityThresholds {
a: 8.5,
b: 7.0,
c: 5.5,
d: 4.0,
};
static SMARTPHONE_BASIS: RegulatoryBasis = RegulatoryBasis {
regulation: "Non-regulatory: simplified repairability heuristic (NOT EU 2023/1669 Annex IV)",
article: "Six-factor heuristic — disassembly, spare parts, repair info, \
diagnostic tools, software updates, customer support",
standard: None,
technical_study: None,
source_url: None,
superseded_by: None,
};
static SMARTPHONE_RULESET_ID: std::sync::OnceLock<RulesetId> = std::sync::OnceLock::new();
static SMARTPHONE_RULESET_VERSION: std::sync::OnceLock<RulesetVersion> = std::sync::OnceLock::new();
static SMARTPHONE_EFFECTIVE_DATES: std::sync::OnceLock<EffectiveDateBound> =
std::sync::OnceLock::new();
pub struct SimplifiedRepairabilityHeuristic;
impl Ruleset for SimplifiedRepairabilityHeuristic {
fn id(&self) -> &RulesetId {
SMARTPHONE_RULESET_ID.get_or_init(|| RulesetId("repairability-heuristic-v1".into()))
}
fn version(&self) -> &RulesetVersion {
SMARTPHONE_RULESET_VERSION.get_or_init(|| RulesetVersion("1.0.0".into()))
}
fn effective_dates(&self) -> &EffectiveDateBound {
SMARTPHONE_EFFECTIVE_DATES.get_or_init(|| {
EffectiveDateBound::open(NaiveDate::from_ymd_opt(2025, 6, 20).expect("valid date"))
})
}
fn regulatory_basis(&self) -> &RegulatoryBasis {
&SMARTPHONE_BASIS
}
}
impl RepairabilityRuleset for SimplifiedRepairabilityHeuristic {
fn weights(&self) -> &RepairabilityWeights {
&SMARTPHONE_WEIGHTS
}
fn thresholds(&self) -> &RepairabilityThresholds {
&SMARTPHONE_THRESHOLDS
}
fn validate_cross_fields(&self, inputs: &RepairabilityInputs) -> Result<(), CalcError> {
if inputs.disassembly == 0 && inputs.spare_parts > 0 {
return Err(CalcError::CrossFieldViolation(
"spare_parts requires disassembly ≥ 1: parts are inaccessible \
without disassembly instructions"
.into(),
));
}
Ok(())
}
}