//! Reason of a [`Room`] closing.
//!
//! [`Room`]: room::Room

use derive_more::with_trait::From;
use wasm_bindgen::prelude::*;

use crate::{api::RoomCloseKind, room};

/// Reason of why a [`Room`] is closed.
///
/// This struct is passed to a [`RoomHandle::on_close`] JS side callback.
///
/// [`Room`]: room::Room
/// [`RoomHandle::on_close`]: crate::api::RoomHandle::on_close
#[wasm_bindgen]
#[derive(Clone, Copy, Debug, From)]
pub struct RoomCloseReason(room::RoomCloseReasonImpl);

#[expect( // `wasm_bindgen` doesn't support `const fn`
    clippy::missing_const_for_fn,
    reason = "`wasm_bindgen` doesn't support `const fn`"
)]
#[wasm_bindgen]
impl RoomCloseReason {
    /// Returns the [`Room`]'s close reason.
    ///
    /// [`Room`]: room::Room
    #[must_use]
    pub fn reason(&self) -> RoomCloseKind {
        self.0.reason()
    }

    /// Indicates whether the [`Room`] was closed by server.
    ///
    /// [`Room`]: room::Room
    #[must_use]
    pub fn is_closed_by_server(&self) -> bool {
        self.0.is_closed_by_server()
    }
}
