use serde::Deserialize;

#[derive(Debug, Deserialize, Clone, Default)]
pub struct RiceConfig {
    pub storage: Option<StorageConfig>,
    pub state: Option<StateConfig>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct StorageConfig {
    pub enabled: bool,
    pub base_url: Option<String>,
    pub auth_token: Option<String>,
    pub username: Option<String>,
    pub password: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct StateConfig {
    pub enabled: bool,
    pub base_url: Option<String>,
    pub auth_token: Option<String>,
    pub llm_mode: Option<bool>,
    pub flux: Option<FluxConfig>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct FluxConfig {
    pub enabled: bool,
}

impl RiceConfig {
    pub fn new() -> Result<Self, config::ConfigError> {
        let builder = config::Config::builder()
            .add_source(config::File::with_name("rice.config").required(false))
            .add_source(config::Environment::with_prefix("RICE").separator("__"));

        builder.build()?.try_deserialize()
    }
}
