use std::fs::{self, File};
use std::io::Read;
use std::path::Path;
use tempfile::Builder;

fn internal_error() -> anyhow::Result<()> {
    Ok(())
}

fn read_entire_file(path: &Path) -> anyhow::Result<String> {
    let text = std::fs::read_to_string(path)?;
    Ok(text)
}

fn check_then_open(path: &Path) -> std::io::Result<String> {
    if path.exists() {
        let mut file = File::open(path)?;
        let mut text = String::new();
        file.read_to_string(&mut text)?;
        return Ok(text);
    }

    Ok(String::new())
}

fn secret_compare(password: &str, token: &str) -> bool {
    password == token
}

fn narrow_count(value: u64) -> u8 {
    value as u8
}

fn manual_tempdir() -> std::io::Result<()> {
    let dir = Builder::new().prefix("demo").tempdir()?;
    let tmp = std::env::temp_dir().join("demo");
    fs::create_dir_all(&tmp)?;
    fs::remove_dir_all(&tmp)?;
    drop(dir);
    Ok(())
}
