1use std::time::Duration;
2
3use crate::error::{Result, RuntimeError};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum RuntimeMode {
8 Development,
9 Production,
10}
11
12#[derive(Debug, Clone)]
14pub enum AuthConfig {
15 BearerToken(String),
16 Basic { username: String, password: String },
17 CustomHeader { key: String, value: String },
18}
19
20#[derive(Debug, Clone)]
22pub struct RuntimeConfig {
23 pub base_url: String,
24 pub timeout: Duration,
25 pub connect_timeout: Duration,
26 pub max_retries: usize,
27 pub max_concurrent: usize,
28 pub auto_pull: bool,
29 pub mode: RuntimeMode,
30 pub auth: Option<AuthConfig>,
31}
32
33impl RuntimeConfig {
34 pub fn validate(&self) -> Result<()> {
37 if self.mode == RuntimeMode::Production && self.auto_pull {
38 return Err(RuntimeError::Other(
39 "auto_pull must be disabled in Production mode".into(),
40 ));
41 }
42 if self.max_concurrent == 0 {
43 return Err(RuntimeError::Other(
44 "max_concurrent must be at least 1".into(),
45 ));
46 }
47 Ok(())
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54 use std::time::Duration;
55
56 #[test]
57 fn rejects_production_with_auto_pull() {
58 let cfg = RuntimeConfig {
59 base_url: "http://127.0.0.1:11434".into(),
60 timeout: Duration::from_secs(1),
61 connect_timeout: Duration::from_secs(1),
62 max_retries: 0,
63 max_concurrent: 1,
64 auto_pull: true,
65 mode: RuntimeMode::Production,
66 auth: None,
67 };
68 assert!(cfg.validate().is_err());
69 }
70}