use std::path::PathBuf;
use reqwest::multipart;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
pub async fn simulate_api_call(contracts: Vec<PathBuf>, markdown_content: String) -> Result<String, String> {
if contracts.is_empty() {
return Err("No contract files provided".to_string());
}
if markdown_content.is_empty() {
return Err("Markdown content is empty".to_string());
}
let mut form = multipart::Form::new()
.text("markdown", markdown_content);
let client = reqwest::Client::new();
for contract in contracts {
let mut file = File::open(&contract).await.map_err(|e| format!("Failed to open contract file: {}", e))?;
let mut contents = vec![];
file.read_to_end(&mut contents).await.map_err(|e| format!("Failed to read contract file: {}", e))?;
let part = multipart::Part::bytes(contents).file_name(contract.file_name().unwrap().to_str().unwrap().to_string());
form = form.part("contracts", part);
}
let response = client.post("https://getibackend.onrender.com/api/audit")
.multipart(form)
.send()
.await;
match response {
Ok(resp) => {
let text = resp.text().await.unwrap();
Ok(format!("Successfully sent contracts and markdown content. Response: {}", text))
},
Err(err) => Err(format!("Failed to send contracts and markdown content. Error: {}", err)),
}
}