use crate::product::utils_absolute_path::AbsolutePathBuf;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;

use crate::product::agent::config::types::Personality;
use crate::product::agent::protocol::AskForApproval;
use crate::product::protocol::config_types::ReasoningSummary;
use crate::product::protocol::config_types::SandboxMode;
use crate::product::protocol::config_types::Verbosity;
use crate::product::protocol::config_types::WebSearchMode;

/// Collection of common configuration options that a user can define as a unit
/// in `config.toml`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
#[schemars(deny_unknown_fields)]
pub struct ConfigProfile {
    pub approval_policy: Option<AskForApproval>,
    pub sandbox_mode: Option<SandboxMode>,
    pub model_reasoning_summary: Option<ReasoningSummary>,
    pub model_verbosity: Option<Verbosity>,
    pub personality: Option<Personality>,
    /// Optional path to a file containing model instructions.
    pub model_instructions_file: Option<AbsolutePathBuf>,
    /// Deprecated: ignored. Use `model_instructions_file`.
    #[schemars(skip)]
    pub experimental_instructions_file: Option<AbsolutePathBuf>,
    pub experimental_compact_prompt_file: Option<AbsolutePathBuf>,
    pub include_apply_patch_tool: Option<bool>,
    pub experimental_use_unified_exec_tool: Option<bool>,
    pub experimental_use_freeform_apply_patch: Option<bool>,
    pub tools_web_search: Option<bool>,
    pub tools_view_image: Option<bool>,
    pub web_search: Option<WebSearchMode>,
    pub analytics: Option<crate::product::agent::config::types::AnalyticsConfigToml>,
    /// Optional feature toggles scoped to this profile.
    #[serde(default)]
    // Injects known feature keys into the schema and forbids unknown keys.
    #[schemars(schema_with = "crate::product::agent::config::schema::features_schema")]
    pub features: Option<crate::product::agent::features::FeaturesToml>,
    /// Deprecated: accepted for backward compatibility and ignored.
    #[serde(default)]
    #[schemars(skip)]
    pub oss_provider: Option<String>,
}

impl From<ConfigProfile> for crate::product::app_server_protocol::Profile {
    fn from(config_profile: ConfigProfile) -> Self {
        Self {
            approval_policy: config_profile.approval_policy,
            model_reasoning_summary: config_profile.model_reasoning_summary,
            model_verbosity: config_profile.model_verbosity,
        }
    }
}
