use mockforge_registry_core::models::BYOKConfig;
#[derive(Debug, Clone)]
pub enum Provider {
Byok(BYOKConfig),
Platform,
Disabled,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProviderSelection {
Byok,
Platform,
Disabled,
}
impl Provider {
pub fn selection(&self) -> ProviderSelection {
match self {
Provider::Byok(_) => ProviderSelection::Byok,
Provider::Platform => ProviderSelection::Platform,
Provider::Disabled => ProviderSelection::Disabled,
}
}
}
pub fn pick_provider(is_paid_plan: bool, byok: Option<BYOKConfig>) -> Provider {
match (is_paid_plan, byok) {
(_, Some(cfg)) if cfg.enabled => Provider::Byok(cfg),
(true, _) => Provider::Platform,
(false, _) => Provider::Disabled,
}
}
#[cfg(test)]
mod tests {
use super::*;
fn enabled_byok() -> BYOKConfig {
BYOKConfig {
provider: "openai".into(),
api_key: "encrypted-test-key".into(),
base_url: None,
model: Some("gpt-4o-mini".into()),
enabled: true,
}
}
fn disabled_byok() -> BYOKConfig {
BYOKConfig {
enabled: false,
..enabled_byok()
}
}
#[test]
fn free_plus_byok_uses_byok() {
let p = pick_provider(false, Some(enabled_byok()));
assert!(matches!(p, Provider::Byok(_)));
assert_eq!(p.selection(), ProviderSelection::Byok);
}
#[test]
fn free_without_byok_is_disabled() {
let p = pick_provider(false, None);
assert!(matches!(p, Provider::Disabled));
}
#[test]
fn free_with_disabled_byok_is_disabled() {
let p = pick_provider(false, Some(disabled_byok()));
assert!(matches!(p, Provider::Disabled));
}
#[test]
fn paid_plus_byok_prefers_byok() {
let p = pick_provider(true, Some(enabled_byok()));
assert!(matches!(p, Provider::Byok(_)));
}
#[test]
fn paid_without_byok_uses_platform() {
let p = pick_provider(true, None);
assert!(matches!(p, Provider::Platform));
}
#[test]
fn paid_with_disabled_byok_uses_platform() {
let p = pick_provider(true, Some(disabled_byok()));
assert!(matches!(p, Provider::Platform));
}
}