//! Events emitted from the Core Engine to Bevy

use crate::networking::{NodeId, SessionId, VectorClock};
use bevy::prelude::*;
use uuid::Uuid;

/// Events that the Core Engine emits to Bevy
#[derive(Debug, Clone)]
pub enum EngineEvent {
    // Networking status
    NetworkingStarted {
        session_id: SessionId,
        node_id: NodeId,
    },
    NetworkingFailed {
        error: String,
    },
    NetworkingStopped,
    SessionJoined {
        session_id: SessionId,
    },
    SessionLeft,

    // Peer events
    PeerJoined {
        node_id: NodeId,
    },
    PeerLeft {
        node_id: NodeId,
    },

    // CRDT sync events
    EntitySpawned {
        entity_id: Uuid,
        position: Vec3,
        rotation: Quat,
        version: VectorClock,
    },
    EntityUpdated {
        entity_id: Uuid,
        position: Vec3,
        rotation: Quat,
        version: VectorClock,
    },
    EntityDeleted {
        entity_id: Uuid,
        version: VectorClock,
    },

    // Lock events
    LockAcquired {
        entity_id: Uuid,
        holder: NodeId,
    },
    LockReleased {
        entity_id: Uuid,
    },
    LockDenied {
        entity_id: Uuid,
        current_holder: NodeId,
    },
    LockExpired {
        entity_id: Uuid,
    },

    // Clock events
    ClockTicked {
        sequence: u64,
        clock: VectorClock,
    },
}
