//! `movement_detector` — ego-motion compensated residual-motion clustering.
//!
//! Real implementation lands in:
//! - AZ-662 `movement_detector_ego_motion`
//! - AZ-663 `movement_detector_clustering_and_emission`
//! - AZ-664 `movement_detector_fp_cap_and_q14_fallback`

use tokio::sync::broadcast;

use shared::health::ComponentHealth;
use shared::models::movement::MovementCandidate;

const NAME: &str = "movement_detector";

pub struct MovementDetector {
    tx: broadcast::Sender<MovementCandidate>,
}

impl MovementDetector {
    pub fn new(channel_capacity: usize) -> Self {
        let (tx, _rx) = broadcast::channel(channel_capacity);
        Self { tx }
    }

    pub fn handle(&self) -> MovementDetectorHandle {
        MovementDetectorHandle {
            tx: self.tx.clone(),
        }
    }
}

#[derive(Clone)]
pub struct MovementDetectorHandle {
    tx: broadcast::Sender<MovementCandidate>,
}

impl MovementDetectorHandle {
    pub fn candidates(&self) -> broadcast::Receiver<MovementCandidate> {
        self.tx.subscribe()
    }

    pub fn health(&self) -> ComponentHealth {
        ComponentHealth::disabled(NAME)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_compiles() {
        let h = MovementDetector::new(16).handle();
        assert_eq!(h.health().level, shared::health::HealthLevel::Disabled);
    }
}
