pub mod mock;

#[cfg(not(test))]
pub mod pgrx;

use serde_json::Value;

/// An abstraction over database execution to allow for isolated unit testing
/// without a live Postgres SPI connection.
pub trait DatabaseExecutor: Send + Sync {
  /// Executes a query expecting a single JSONB return, representing rows.
  fn query(&self, sql: &str, args: Option<&[Value]>) -> Result<Value, String>;

  /// Executes an operation (INSERT, UPDATE, DELETE, or pg_notify) that does not return rows.
  fn execute(&self, sql: &str, args: Option<&[Value]>) -> Result<(), String>;

  /// Returns the current authenticated user's ID
  fn auth_user_id(&self) -> Result<String, String>;

  /// Returns the current transaction timestamp
  fn timestamp(&self) -> Result<String, String>;

  #[cfg(test)]
  fn get_queries(&self) -> Vec<String>;

  #[cfg(test)]
  fn reset_mocks(&self);
}
