use embassy_sync::pubsub::DynPublisher;
use embassy_time::Timer;

use crate::{ego::engine::MotionState, events::{Personality, Prediction, SensorSource, SensorState}};


#[embassy_executor::task]
pub async fn demo_task(ui: DynPublisher<'static, Prediction>) {
    ui.publish(Prediction::SensorStatus(SensorSource::Demo, SensorState::AcquiringFix)).await;
    Timer::after_secs(10).await;
    ui.publish(Prediction::SetPersonality(crate::events::Personality::Active)).await;
    Timer::after_secs(10).await;
    ui.publish(Prediction::SensorStatus(SensorSource::Demo, SensorState::Online)).await;
    loop {
        for personality in [Personality::Active, Personality::Parked] {
            ui.publish(Prediction::SetPersonality(personality)).await;
            for state in [SensorState::Offline, SensorState::AcquiringFix, SensorState::Degraded, SensorState::Offline] {
                for motion in [MotionState::Accelerating, MotionState::Steady, MotionState::Decelerating, MotionState::Stationary] {
                    ui.publish(Prediction::Motion { prev: motion, next: motion }).await;
                    for sensor in [SensorSource::MotionFrame, SensorSource::GPS, SensorSource::IMU, SensorSource::Location] {
                        ui.publish(Prediction::SensorStatus(sensor, state)).await;
                    }
                    Timer::after_secs(1).await;
                }   
            }
        }
    }
}