use_prelude!();
use std::sync::{Arc, Weak};

use super::{v2::V2Presence, v3::PresenceGraph};

/// A token returned by `Presence::observe`. Retain this object to continue
/// receiving callback updates.
pub struct PresenceObserver {
    _ctx: Arc<PresenceObserverCtx>,
}
pub(crate) type WeakPresenceObserver = Weak<PresenceObserverCtx>;

impl PresenceObserver {
    pub(crate) fn new(_ctx: Arc<PresenceObserverCtx>) -> Self {
        Self { _ctx }
    }
}

impl Observer for PresenceObserver {}

pub(crate) struct PresenceObserverCtx {
    pub(crate) on_presence: Box<dyn Fn(&PresenceGraph) + Send + Sync + 'static>,
}

impl PresenceObserverCtx {
    pub(crate) fn new(on_presence: Box<dyn Fn(&PresenceGraph) + Send + Sync + 'static>) -> Self {
        Self { on_presence }
    }
}

// A token returned by `observe_peers`. Retain this object to continue
/// receiving callback updates.
pub struct PeersObserver {
    _context: Arc<PeersObserverCtx>,
}

impl PeersObserver {
    pub(crate) fn new(context: Arc<PeersObserverCtx>) -> Self {
        Self { _context: context }
    }
}

impl Observer for PeersObserver {}

pub(crate) struct PeersObserverCtx {
    pub(crate) on_presence: Box<dyn Fn(V2Presence) + Send + Sync + 'static>,
}

impl PeersObserverCtx {
    pub(crate) fn new(on_presence: Box<dyn Fn(V2Presence) + Send + Sync + 'static>) -> Self {
        Self { on_presence }
    }
}
