use std::error::Error;
use std::path::Path;
fn main() -> Result<(), Box<dyn Error>> {
        let proto_files = glob::glob("proto/**/*.proto")?
        .collect::<Result<Vec<_>, _>>()?;
    
    if proto_files.is_empty() {
        return Err("No .proto files found in the proto directory".into());
    }
    
        for proto_file in &proto_files {
        println!("cargo:rerun-if-changed={}", proto_file.display());
    }
    
            let proto_include_dir = Path::new("proto");
    
        let config = tonic_build::configure()
        .build_server(true)
        .build_client(true);
        
        let proto_paths: Vec<String> = proto_files
        .iter()
        .map(|path| path.to_string_lossy().to_string())
        .collect();
    
        config.compile_protos(&proto_paths, &[proto_include_dir])?;
    
    Ok(())
}