use crate::model::block::BlockId;

/// Trait for generating unique block IDs. Injected for deterministic testing.
pub trait IdGenerator {
    fn next_id(&mut self) -> BlockId;
}

/// Production ID generator using UUID v7 (timestamp-sortable, collision-safe for distributed systems).
pub struct UuidGenerator;

impl IdGenerator for UuidGenerator {
    fn next_id(&mut self) -> BlockId {
        BlockId::new(uuid::Uuid::now_v7().to_string())
    }
}

/// Test ID generator producing sequential IDs.
pub struct SequentialIdGenerator {
    counter: usize,
    prefix: String,
}

impl SequentialIdGenerator {
    pub fn new(prefix: &str) -> Self {
        Self {
            counter: 0,
            prefix: prefix.to_string(),
        }
    }
}

impl IdGenerator for SequentialIdGenerator {
    fn next_id(&mut self) -> BlockId {
        self.counter += 1;
        BlockId::new(format!("{}-{}", self.prefix, self.counter))
    }
}
