use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::error::Error;
#[derive(Serialize)]
struct TranslationRequest {
text: String,
target_language: String,
}
#[derive(Deserialize)]
struct TranslationResponse {
translation: String,
}
pub async fn translate(text: &str, target_language: &str, api_key: &str) -> Result<String, Box<dyn Error>> {
let client = Client::new();
let request = TranslationRequest {
text: text.to_string(),
target_language: target_language.to_string(),
};
let response = client
.post("https://safi.insolify.com/translation")
.json(&request)
.bearer_auth(api_key)
.send()
.await?;
let translation_response: TranslationResponse = response.json().await?;
Ok(translation_response.translation)
}