use cu29::prelude::*;
use cu29_derive::copper_runtime;

#[derive(Reflect)]
struct Source;

impl Freezable for Source {}

impl CuSrcTask for Source {
    type Resources<'r> = ();
    type Output<'m> = output_msg!(i32);

    fn new(_config: Option<&ComponentConfig>, _resources: Self::Resources<'_>) -> CuResult<Self> {
        Ok(Self)
    }

    fn process(&mut self, _ctx: &CuContext, output: &mut Self::Output<'_>) -> CuResult<()> {
        output.set_payload(1);
        Ok(())
    }
}

#[derive(Reflect)]
struct Proc;

impl Freezable for Proc {}

impl CuTask for Proc {
    type Resources<'r> = ();
    type Input<'m> = input_msg!(i32);
    type Output<'m> = output_msg!(i32);

    fn new(_config: Option<&ComponentConfig>, _resources: Self::Resources<'_>) -> CuResult<Self> {
        Ok(Self)
    }

    fn process(
        &mut self,
        _ctx: &CuContext,
        input: &Self::Input<'_>,
        output: &mut Self::Output<'_>,
    ) -> CuResult<()> {
        if let Some(value) = input.payload() {
            output.set_payload(*value);
        }
        Ok(())
    }
}

#[copper_runtime(
    config = "config/ignore_resources_sim_mode_valid.ron",
    sim_mode = true,
    ignore_resources = true
)]
struct App {}
fn main() {}
