// notional_walk_hdr — taker market orders specified by quote-notional
// amount sweep multi-level book. Mirrors `aggressive_walk_hdr` but uses
// the `match_market_order_by_amount_with_user` path so we can compare
// p50 / p99 / p99.9 / p99.99 against the base-quantity sweep on the
// same book shape.

#[path = "hdr_common.rs"]
mod common;

use common::{Rng, new_histogram, owner, persist, record, report};
use pricelevel::{Id, Side, TimeInForce};

const SCENARIO: &str = "notional_walk";
const RESTING_PER_LEVEL: u64 = 100;
const NUM_LEVELS: u64 = 50;
const MEASURED_OPS: u64 = 100_000;
const SEED: u64 = 0xC1_C1_C1_C1_C1_C1_C1_C1;

fn main() {
    let book = common::fresh_book();
    let mut rng = Rng::new(SEED);
    let mut hist = new_histogram();
    let maker = owner(0xAA);
    let taker = owner(0xBB);

    // Seed RESTING_PER_LEVEL asks at each of NUM_LEVELS prices.
    let mut next_id = 1u64;
    for level in 0..NUM_LEVELS {
        let price = (100 + level) as u128;
        for _ in 0..RESTING_PER_LEVEL {
            let _ = book.add_limit_order_with_user(
                Id::from_u64(next_id),
                price,
                rng.range(1, 10),
                Side::Sell,
                TimeInForce::Gtc,
                maker,
                None,
            );
            next_id += 1;
        }
    }

    // Aggressive notional Buy sweeps. Random budgets in [500, 2_000)
    // quote ticks — usually clear a few orders at the best level or
    // walk into the next.
    for i in 0..MEASURED_OPS {
        let amount = rng.range(500, 2_000) as u128;
        let id = Id::from_u64(next_id + i);
        record(&mut hist, || {
            let _ = book.submit_market_order_by_amount_with_user(id, amount, Side::Buy, taker);
        });
    }

    report(SCENARIO, &hist);
    persist(SCENARIO, &hist).expect("persist hgrm");
}
