use armdb::{Config, FixedConfig};

/// Bounded block cache for Var hot/cold profiles (full target). The default
/// `CacheConfig::max_size` is 0 (cache disabled), which erases the hot/cold
/// distinction — so we always set a finite, non-zero size here.
/// Note: reused by the quick target too; the quick target has no cold profile so the size does not affect quick result quality.
pub const FULL_CACHE_BYTES: u64 = 8 * 1024 * 1024; // 8 MiB

/// Page-cache profile: `enable_fsync=false`, `direct_io=false`.
/// Also sets a bounded block cache so Var* reads have a real hot path.
pub fn page_cache_config() -> Config {
    let mut c = Config::test();
    c.enable_fsync = false;
    c.direct_io = false;
    #[cfg(feature = "var-collections")]
    {
        c.block_cache.max_size = FULL_CACHE_BYTES;
    }
    c.validate().expect("page_cache_config must be valid");
    c
}

/// Direct-I/O profile: `enable_fsync=false`, `direct_io=true`. The default
/// 1 MiB write buffer already satisfies the page-alignment validation rules.
/// If the filesystem rejects O_DIRECT the storage layer falls back to buffered
/// I/O; the benchmark name still reports `direct_io` (see spec).
pub fn direct_io_config() -> Config {
    let mut c = Config::test();
    c.enable_fsync = false;
    c.direct_io = true;
    #[cfg(feature = "var-collections")]
    {
        c.block_cache.max_size = FULL_CACHE_BYTES;
    }
    c.validate().expect("direct_io_config must be valid");
    c
}

/// Pick a Bitcask config by mode flag.
pub fn bitcask_config(direct_io: bool) -> Config {
    if direct_io {
        direct_io_config()
    } else {
        page_cache_config()
    }
}

/// FixedStore config for benchmarks. FixedStore does not support
/// direct_io/encryption; it has its own config model (`enable_fsync=false`).
///
/// Deliberately NOT `FixedConfig::test()`: that config sets `grow_step = 1_000`
/// (vs the 1_000_000 default) to keep fd/space usage low for unit tests, which
/// forces a file grow roughly every 1000 inserts. Under a long-lived write
/// benchmark that growth dominates the timings and makes FixedStore look ~10x
/// slower than it is. Here we use the default realistic `grow_step` and sync
/// settings, and pin `shard_count = 2` to match the Bitcask `Config::test()`
/// shard count for a fair cross-backend comparison (and to bound fd usage).
pub fn fixed_config() -> FixedConfig {
    let c = FixedConfig {
        shard_count: 2,
        ..FixedConfig::balanced().build()
    };
    c.validate().expect("fixed_config must be valid");
    c
}
