//! Shared Postgres-test plumbing for the integration suite.
//!
//! Every behavioral test runs against the durable runner, gated on
//! `DATABASE_URL` like the rest of the mire integration suite — tests
//! return silently (with a skip note) when it is unset.

#![allow(dead_code)]

use mire::EventStore;

/// Connect + migrate (mire + saga schemas), or `None` with a skip note
/// when `DATABASE_URL` is unset.
pub async fn store() -> Option<EventStore> {
    let Ok(url) = std::env::var("DATABASE_URL") else {
        eprintln!("skipping: DATABASE_URL not set");
        return None;
    };
    let pool = sqlx::PgPool::connect(&url).await.expect("connect postgres");
    let store = EventStore::new(pool);
    store.migrate().await.expect("mire migrate");
    mire_sagas::migrate(&store).await.expect("saga migrate");
    Some(store)
}

/// Unique id so reruns and parallel test binaries never collide on
/// durable instance ids.
pub fn unique(prefix: &str) -> String {
    format!("{prefix}-{}", uuid::Uuid::new_v4().simple())
}
