//! Build `AthenaAuth` with the in-memory adapter and email/password plugin, then POST `/sign-up/email`.

use athena_auth::plugins::EmailPasswordPlugin;
use athena_auth::{AuthBuilder, AuthConfig, AuthRequest, HttpMethod, MemoryDatabaseAdapter};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let config = AuthConfig::new("test-secret-key-that-is-at-least-32-characters-long")
        .base_url("http://localhost:3000");

    let auth = AuthBuilder::new(config)
        .database(MemoryDatabaseAdapter::new())
        .plugin(EmailPasswordPlugin::new().enable_signup(true))
        .build()
        .await?;

    let mut req = AuthRequest::new(HttpMethod::Post, "/sign-up/email");
    req.body =
        Some(br#"{"name":"Demo","email":"demo@example.com","password":"password123"}"#.to_vec());
    req.headers
        .insert("content-type".to_string(), "application/json".to_string());

    let resp = auth.handle_request(req).await?;
    println!(
        "HTTP {} — {}",
        resp.status,
        String::from_utf8_lossy(&resp.body)
    );
    Ok(())
}
