// FILE:    main.rs
// PURPOSE: Binary entry point for ENCRYPTION_SERVICE testing
// GOAL:    Test encryption and decryption operations
// RUNS TO:  Executable entry point via cargo run

// ═══════════════════════════════════════════════════════════════════════════════════════
// KEY FEATURES & DESIGN DECISIONS
// ═══════════════════════════════════════════════════════════════════════════════

// 1. End-to-End Encryption Test
// - Encrypts and decrypts plaintext
// - Encrypts and decrypts JSON fields
// - WHY: Verifies encryption service correctness

// 2. Async Main
// - Uses tokio::main for async runtime
// - WHY: Required for async encryption operations

// ── IMPORTS ──────────────────────────────────────────────────────────────────
// Three groups: stdlib · third-party · internal

use anyhow::Result;

// ── internal ─────────────────────────────────────────────────────────────────
use encryption_service::encryption_service::Aes256CtrEncryption;

// ── MAIN ──────────────────────────────────────────────────────────────────
// Goal: Test encryption and decryption operations

#[tokio::main]
async fn main() -> Result<()> {
    dotenvy::dotenv().ok();
    println!("Testing encryption_service...");

    let plaintext = "Hello, World!";
    let token = Aes256CtrEncryption::encrypt_content(plaintext).await?;
    println!("Encrypted: {}", token);

    let recovered = Aes256CtrEncryption::decrypt_content(&token).await?;
    println!("Decrypted: {}", recovered);
    assert_eq!(plaintext, recovered);

    let json_value =
        Aes256CtrEncryption::encrypt_to_json_field("s3cr3tP@ss", "user.credentials.password")
            .await?;
    println!("Encrypted JSON: {}", json_value);

    let field_recovered =
        Aes256CtrEncryption::decrypt_json_field(&json_value, "user.credentials.password").await?;
    println!("Decrypted field: {}", field_recovered);
    assert_eq!("s3cr3tP@ss", field_recovered);

    println!("Done — all encryption/decryption operations completed successfully");
    Ok(())
}