use crate::render::wgpu::rendergraph::{PassExecutionContext, PassNode};

/// Declares frame-end reads on `entity_id` and `depth` so the render graph
/// keeps storing them when a GPU pick is pending. The pick compute samples
/// both textures after the graph finishes, outside any pass, so without this
/// node the graph would see no later reader and discard their contents at the
/// end of the geometry passes. The pass records no commands itself, and the
/// renderer disables it on frames with no pending pick request so the
/// geometry passes can skip those tile stores entirely.
#[derive(Default)]
pub struct PickKeepalivePass;

impl PickKeepalivePass {
    pub fn new() -> Self {
        Self
    }
}

impl PassNode<crate::ecs::world::World> for PickKeepalivePass {
    fn name(&self) -> &str {
        "pick_keepalive_pass"
    }

    fn reads(&self) -> Vec<&str> {
        vec![]
    }

    fn writes(&self) -> Vec<&str> {
        vec![]
    }

    fn reads_writes(&self) -> Vec<&str> {
        vec!["entity_id", "depth"]
    }

    fn execute<'r, 'e>(
        &mut self,
        context: PassExecutionContext<'r, 'e, crate::ecs::world::World>,
    ) -> crate::render::wgpu::rendergraph::Result<
        Vec<crate::render::wgpu::rendergraph::SubGraphRunCommand<'r>>,
    > {
        Ok(context.into_sub_graph_commands())
    }
}
