use std::collections::HashMap;
use serde::{ Serialize, Deserialize };
use core::time::Duration;
use crate::error::Result;
#[ derive( Debug, Clone ) ]
pub struct ApiConnectorConfig
{
pub base_url : String,
pub authentication : ApiAuthentication,
pub rate_limits : Option< RateLimitConfig >,
pub retry_config : Option< RetryConfig >,
}
#[ derive( Debug, Clone ) ]
pub enum ApiAuthentication
{
None,
ApiKey
{
header : String,
key : String,
},
Bearer
{
token : String,
},
OAuth2
{
client_id : String,
client_secret : String,
},
Custom
{
headers : HashMap< String, String >,
},
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct RateLimitConfig
{
pub requests_per_minute : u32,
pub requests_per_hour : u32,
pub burst_limit : u32,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct RetryConfig
{
pub max_retries : u32,
pub base_delay : Duration,
pub max_delay : Duration,
pub backoff_factor : f64,
}
#[ async_trait::async_trait ]
pub trait ApiConnector : Send + Sync
{
fn name( &self ) -> &str;
fn config( &self ) -> &ApiConnectorConfig;
async fn make_request(
&self,
method : &str,
endpoint : &str,
body : Option< serde_json::Value >
) -> Result< serde_json::Value >;
}