use crate::core::Value;
use std::path::Path;

pub fn exists(file: &Path) -> Value {
    Value::BooleanValue(file.exists() && file.is_file())
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::fs::File;
    use tempfile::tempdir;

    #[test]
    fn returns_true_when_file_exists() {
        let dir = tempdir().unwrap();
        let path = dir.path().join("file.txt");
        File::create(&path).unwrap();
        assert_eq!(exists(&path), Value::BooleanValue(true));
    }

    #[test]
    fn returns_false_when_file_does_not_exist() {
        let dir = tempdir().unwrap();
        let path = dir.path().join("file.txt");
        assert_eq!(exists(&path), Value::BooleanValue(false));
    }
}
