use std::io::Result;

fn main() -> Result<()> {
    // Build gRPC service definitions for E2E test clients (Tonic 0.14+)
    tonic_prost_build::configure()
        .build_server(false) // We only need clients for E2E tests
        .build_client(true)
        .out_dir("src/proto")
        // Suppress warnings in generated code
        .server_mod_attribute(".", "#[allow(unused_qualifications)]")
        .client_mod_attribute(".", "#[allow(unused_qualifications)]")
        .compile_protos(
            &[
                "../../proto/trading.proto",
                "../../proto/config.proto",
                "../../proto/risk.proto",
                "../../proto/ml_training.proto",
            ],
            &["../../proto"],
        )?;

    // Build TLI protos separately (backtesting service uses TLI proto)
    tonic_prost_build::configure()
        .build_server(false)
        .build_client(true)
        .out_dir("src/proto")
        .server_mod_attribute(".", "#[allow(unused_qualifications)]")
        .client_mod_attribute(".", "#[allow(unused_qualifications)]")
        .compile_protos(&["../../proto/fxt_trading.proto"], &["../../proto"])?;

    println!("cargo:rerun-if-changed=../../proto/");
    Ok(())
}
