// @generated - manually created as documentation example. Do not auto-generate.
//! Module containing [`ButtonWatchGenerated`], the sample struct type generated by the
//! [`button_watch!`](crate::button_watch!) macro.
//!
//! This file shows what the macro expansion looks like for documentation purposes.

#[cfg(all(not(doc), not(feature = "host")))]
use crate::button_watch;

#[cfg(all(not(doc), not(feature = "host")))]
button_watch! {
    pub ButtonWatchGenerated {
        pin: PIN_13,
    }
}

#[cfg(doc)]
/// Sample struct type generated by the [`button_watch!`](crate::button_watch!) macro, showing all methods.
///
/// This page serves as the definitive reference for what a generated button watch type
/// provides. For first-time readers, start with the examples in the [`button_watch!`](crate::button_watch!) macro
/// documentation, then return here for a complete list of available methods.
pub struct ButtonWatchGenerated {
    button_watch: super::ButtonWatch,
}

#[cfg(doc)]
impl ButtonWatchGenerated {
    /// Creates a new button monitor and spawns its background task.
    ///
    /// # Parameters
    ///
    /// - `pin`: GPIO pin for the button
    /// - `pressed_to`: How the button is wired ([`PressedTo::Ground`](crate::button::PressedTo::Ground) or [`PressedTo::Voltage`](crate::button::PressedTo::Voltage))
    /// - `spawner`: Task spawner for background operations
    ///
    /// # Errors
    ///
    /// Returns an error if the background task cannot be spawned.
    ///
    /// # Example
    ///
    /// See the [`button_watch!`](crate::button_watch!) macro for usage.
    pub fn new(
        pin: impl Into<embassy_rp::Peri<'static, embassy_rp::peripherals::PIN_13>>,
        pressed_to: crate::button::PressedTo,
        spawner: embassy_executor::Spawner,
    ) -> crate::Result<&'static Self> {
        static INSTANCE: ButtonWatchGenerated = ButtonWatchGenerated {
            button_watch: super::ButtonWatch {
                signal: &embassy_sync::signal::Signal::new(),
            },
        };
        let _ = (pin, pressed_to, spawner);
        Ok(&INSTANCE)
    }

    /// A device abstraction for buttons that uses a background task to monitor presses.
    ///
    /// This is useful for converting a `Button` returned from `WifiAuto::connect()`
    /// into a `ButtonWatch` for background monitoring.
    ///
    /// # Parameters
    ///
    /// - `button`: An existing button (e.g., from `WifiAuto::connect()`)
    /// - `spawner`: Task spawner for background operations
    ///
    /// # Errors
    ///
    /// Returns an error if the background task cannot be spawned.
    pub fn from_button(
        button: crate::button::Button<'static>,
        spawner: embassy_executor::Spawner,
    ) -> crate::Result<&'static Self> {
        static INSTANCE: ButtonWatchGenerated = ButtonWatchGenerated {
            button_watch: super::ButtonWatch {
                signal: &embassy_sync::signal::Signal::new(),
            },
        };
        let _ = (button, spawner);
        Ok(&INSTANCE)
    }
}

#[cfg(doc)]
impl core::ops::Deref for ButtonWatchGenerated {
    type Target = super::ButtonWatch;

    fn deref(&self) -> &Self::Target {
        &self.button_watch
    }
}
