use serde::{Deserialize, Serialize};

/// SurrealDB backend selector.
///
/// | Variant | Engine | Use for |
/// |---------|--------|---------|
/// | `Memory` | kv-mem | Tests — non-persistent |
/// | `EmbeddedSurrealKV` | kv-surrealkv | Core relational/graph: orchestrator state, resource tracking |
/// | `EmbeddedRocksDB` | kv-rocksdb | Hot data: AI session state, audit logs, embedding caches |
/// | `Server` | protocol-ws | Remote SurrealDB via WebSocket (multi-node production) |
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(tag = "mode", rename_all = "snake_case")]
pub enum DbConfig {
    #[default]
    Memory,
    /// Embedded SurrealKV — requires feature `embedded-surrealkv`.
    EmbeddedSurrealKV {
        path: String,
    },
    /// Embedded RocksDB — requires feature `embedded-rocksdb`.
    EmbeddedRocksDB {
        path: String,
    },
    Server {
        url: String,
        #[serde(default)]
        namespace: String,
        #[serde(default)]
        database: String,
    },
}

impl DbConfig {
    pub fn server(url: impl Into<String>, namespace: impl Into<String>, database: impl Into<String>) -> Self {
        Self::Server { url: url.into(), namespace: namespace.into(), database: database.into() }
    }

    pub fn surrealkv(path: impl Into<String>) -> Self {
        Self::EmbeddedSurrealKV { path: path.into() }
    }

    pub fn rocksdb(path: impl Into<String>) -> Self {
        Self::EmbeddedRocksDB { path: path.into() }
    }
}
