//! `frame_ingest` — RTSP pull + decode + timestamp.
//!
//! Real implementation lands in:
//! - AZ-657 `frame_ingest_rtsp_session`
//! - AZ-658 `frame_ingest_decoder`
//! - AZ-659 `frame_ingest_publisher`

use tokio::sync::broadcast;

use shared::health::ComponentHealth;
use shared::models::frame::Frame;

const NAME: &str = "frame_ingest";

pub struct FrameIngest {
    tx: broadcast::Sender<Frame>,
}

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

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

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

impl FrameIngestHandle {
    /// Subscribe to the frame stream. Consumers receive every frame after they
    /// subscribed; back-pressure is implemented via broadcast channel lag (see
    /// AZ-659 for the slow-consumer policy).
    pub fn subscribe(&self) -> broadcast::Receiver<Frame> {
        self.tx.subscribe()
    }

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

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

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