use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ScriptSource {
    File { path: String },
    Embedded { source: String },
}

impl Default for ScriptSource {
    fn default() -> Self {
        ScriptSource::Embedded {
            source: String::new(),
        }
    }
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Script {
    pub source: ScriptSource,
    #[serde(default)]
    pub enabled: bool,
}

impl Script {
    pub fn from_file(path: impl Into<String>) -> Self {
        Self {
            source: ScriptSource::File { path: path.into() },
            enabled: false,
        }
    }

    pub fn from_source(source: impl Into<String>) -> Self {
        Self {
            source: ScriptSource::Embedded {
                source: source.into(),
            },
            enabled: false,
        }
    }
}
