//! Room-routing decisions for notifications.
//!
//! Pure functions that determine which destination room IDs should receive
//! a given notification.  Currently all notification kinds are broadcast to
//! all registered rooms; this module is the single location to change that
//! policy if per-event routing is needed in the future.

/// Return the rooms that should receive a notification.
///
/// `get_room_ids` is called once per notification to obtain the current list
/// of destination room IDs.  Passing a closure (rather than a static slice)
/// allows callers to use a runtime-mutable set, e.g. WhatsApp ambient senders.
///
/// All currently supported event kinds are broadcast to every room returned
/// by the closure.
pub fn rooms_for_notification(get_room_ids: &impl Fn() -> Vec<String>) -> Vec<String> {
    get_room_ids()
}

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

    #[test]
    fn returns_all_rooms_from_closure() {
        let rooms = rooms_for_notification(&|| vec!["room1".to_string(), "room2".to_string()]);
        assert_eq!(rooms, vec!["room1".to_string(), "room2".to_string()]);
    }

    #[test]
    fn returns_empty_when_no_rooms_registered() {
        let rooms = rooms_for_notification(&Vec::new);
        assert!(rooms.is_empty());
    }

    #[test]
    fn returns_single_room() {
        let rooms = rooms_for_notification(&|| vec!["!abc:example.org".to_string()]);
        assert_eq!(rooms.len(), 1);
        assert_eq!(rooms[0], "!abc:example.org");
    }
}
