use std::env;
use serde_json::{Map, Value};
use crate::models::OperationMode;
#[derive(Debug, Clone, Default)]
pub struct ClientConfig {
pub api_key: Option<String>,
pub base_url: Option<String>,
pub operation_mode: OperationMode,
pub environments_dir: Option<String>,
pub recordings_dir: Option<String>,
}
impl ClientConfig {
pub fn new() -> Self {
Self::default()
}
pub fn api_key(mut self, key: impl Into<String>) -> Self {
self.api_key = Some(key.into());
self
}
pub fn base_url(mut self, url: impl Into<String>) -> Self {
self.base_url = Some(url.into());
self
}
pub fn operation_mode(mut self, mode: OperationMode) -> Self {
self.operation_mode = mode;
self
}
pub fn environments_dir(mut self, dir: impl Into<String>) -> Self {
self.environments_dir = Some(dir.into());
self
}
pub fn recordings_dir(mut self, dir: impl Into<String>) -> Self {
self.recordings_dir = Some(dir.into());
self
}
pub fn resolved_base_url(&self) -> String {
self.base_url
.clone()
.or_else(|| env::var("ARC_BASE_URL").ok())
.unwrap_or_else(|| "https://three.arcprize.org".to_string())
}
pub fn resolved_api_key(&self) -> String {
self.api_key
.clone()
.or_else(|| env::var("ARC_API_KEY").ok())
.unwrap_or_default()
}
}
#[derive(Debug, Clone, Default)]
pub struct ScorecardParams {
pub source_url: Option<String>,
pub tags: Option<Vec<String>>,
pub opaque: Option<Value>,
pub competition_mode: Option<bool>,
}
impl ScorecardParams {
pub fn new() -> Self {
Self::default()
}
pub fn source_url(mut self, url: impl Into<String>) -> Self {
self.source_url = Some(url.into());
self
}
pub fn tags(mut self, tags: Vec<String>) -> Self {
self.tags = Some(tags);
self
}
pub fn opaque(mut self, data: Value) -> Self {
self.opaque = Some(data);
self
}
pub fn competition_mode(mut self, enabled: bool) -> Self {
self.competition_mode = Some(enabled);
self
}
pub fn to_json_body(&self) -> Value {
let mut map = Map::new();
let tags = self
.tags
.clone()
.unwrap_or_else(|| vec!["agent".to_string()]);
map.insert(
"tags".to_string(),
Value::Array(tags.into_iter().map(Value::String).collect()),
);
if let Some(url) = &self.source_url {
map.insert("source_url".to_string(), Value::String(url.clone()));
}
if let Some(opaque) = &self.opaque {
map.insert("opaque".to_string(), opaque.clone());
}
if let Some(comp) = self.competition_mode {
map.insert("competition_mode".to_string(), Value::Bool(comp));
}
Value::Object(map)
}
}
#[derive(Debug, Clone)]
pub struct MakeParams {
pub game_id: String,
pub scorecard_id: String,
pub guid: Option<String>,
pub seed: u32,
pub save_recording: bool,
pub include_frame_data: bool,
}
impl MakeParams {
pub fn new(game_id: impl Into<String>, scorecard_id: impl Into<String>) -> Self {
Self {
game_id: game_id.into(),
scorecard_id: scorecard_id.into(),
guid: None,
seed: 0,
save_recording: false,
include_frame_data: true,
}
}
pub fn guid(mut self, guid: impl Into<String>) -> Self {
self.guid = Some(guid.into());
self
}
pub fn seed(mut self, seed: u32) -> Self {
self.seed = seed;
self
}
pub fn save_recording(mut self, save: bool) -> Self {
self.save_recording = save;
self
}
pub fn include_frame_data(mut self, include: bool) -> Self {
self.include_frame_data = include;
self
}
}
#[derive(Debug, Clone)]
pub struct StepParams {
pub game_id: String,
pub scorecard_id: String,
pub guid: String,
pub action_id: u32,
pub data: Option<Value>,
pub reasoning: Option<Value>,
}
impl StepParams {
pub fn new(
game_id: impl Into<String>,
scorecard_id: impl Into<String>,
guid: impl Into<String>,
action_id: u32,
) -> Self {
Self {
game_id: game_id.into(),
scorecard_id: scorecard_id.into(),
guid: guid.into(),
action_id,
data: None,
reasoning: None,
}
}
pub fn data(mut self, data: Value) -> Self {
self.data = Some(data);
self
}
pub fn reasoning(mut self, reasoning: Value) -> Self {
self.reasoning = Some(reasoning);
self
}
}