use trazaeo::reliability::{
    compute_backoff_schedule, enforce_monotonic_sequence, retry_with_backoff,
    InMemoryIdempotencyStore, RetryPolicy,
};

/// Runs the entry point for this executable.
fn main() {
    let policy = RetryPolicy {
        max_attempts: 4,
        initial_backoff_ms: 100,
        backoff_multiplier: 2,
    };

    let schedule = compute_backoff_schedule(policy);
    println!("retry_backoff_schedule_ms={schedule:?}");

    let mut attempts = 0;
    let result = retry_with_backoff(policy, |_attempt| {
        attempts += 1;
        if attempts < 3 {
            Err("transient network error")
        } else {
            Ok("stage success")
        }
    });
    println!("retry_result={result:?}");

    let mut idempotency = InMemoryIdempotencyStore::default();
    let first = idempotency.process_once("evt-123", || "processed");
    let second = idempotency.process_once("evt-123", || "duplicate");
    println!("first_process={first:?}");
    println!("second_process={second:?}");

    let ordered = enforce_monotonic_sequence(&[1, 2, 3, 4]);
    let reordered = enforce_monotonic_sequence(&[1, 3, 2, 4]);
    println!("ordered_sequence_check={ordered:?}");
    println!("reordered_sequence_check={reordered:?}");
}
