#![cfg(not(target_arch = "wasm32"))]
use kvstore::{NativeStore, KVStore};

#[tokio::test]
async fn test_native_store_basic() {
    let tmp_dir = tempfile::tempdir().unwrap();
    let path = tmp_dir.path().join("testdb");
    let store = NativeStore::open(path.to_str().unwrap()).unwrap();

    // Test set/get
    store.set("foo", b"bar").await.unwrap();
    let val = store.get("foo").await.unwrap();
    assert_eq!(val, Some(b"bar".to_vec()));

    // Test exists
    assert_eq!(store.contains_key("foo").await.unwrap(), true);
    assert_eq!(store.contains_key("bar").await.unwrap(), false);
    store.remove("foo").await.unwrap();
    assert_eq!(store.get("foo").await.unwrap(), None);

    // Test keys
    store.set("foo", b"bar").await.unwrap();
    store.set("baz", b"qux").await.unwrap();
    let keys = store.keys().await.unwrap();
    assert_eq!(keys.len(), 2);
    assert!(keys.contains(&"foo".to_string()));
    assert!(keys.contains(&"baz".to_string()));

    // Test clear
    store.clear().await.unwrap();
    let keys = store.keys().await.unwrap();
    assert_eq!(keys.len(), 0);
}

#[tokio::test]
async fn test_native_store_persistence() {
    let tmp_dir = tempfile::tempdir().unwrap();
    let path = tmp_dir.path().join("persistdb");
    let db_path = path.to_str().unwrap();
    // First open, set value
    {
        let store = NativeStore::open(db_path).unwrap();
        store.set("persist", b"value").await.unwrap();
    }
    // Reopen and check value
    {
        let store = NativeStore::open(db_path).unwrap();
        let val = store.get("persist").await.unwrap();
        assert_eq!(val, Some(b"value".to_vec()));
    }
}

