const PROTO_FILES: &[&str] = &[
    "proto/tici.proto",
    "proto/tici_internal.proto",
    "proto/schema.proto",
    "proto/reader.proto",
    "proto/import.proto",
];

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Compile proto files
    let mut prost_config = prost_build::Config::new();
    let skip_debug = vec![
        "tici.ShardLocalCacheInfo",
        "tici_internal.ShardProgress",
        "tici.ShardManifestHeader",
        "tici_internal.FragProperty",
        "tici.KeyRange",
        "tici.S3Location",
        "tici_internal.FragMeta",
        "tici.CreateIndexRequest",
        "tici_internal.AppendDeltaFragMetaRequest",
    ];
    prost_config.skip_debug(skip_debug);
    tonic_build::configure()
        .build_server(true) // Generate server code
        .build_client(true) // Generate client code
        .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
        .out_dir("generated") // Output directory for generated code
        .compile_with_config(prost_config, PROTO_FILES, &["proto"])?;

    for proto in PROTO_FILES {
        println!("cargo:rerun-if-changed={proto}");
    }
    println!("cargo:rerun-if-changed=build.rs");

    Ok(())
}
