use ring::digest::{Context, SHA256};
use std::io::Read;

pub fn is_video_file(filename: &str) -> bool {
    let video_extensions = vec![r"\.mp4$", r"\.mkv$", r"\.webm$", r"\.avi$"];

    for ext in video_extensions {
        let regex = regex::Regex::new(ext).unwrap();
        if regex.is_match(filename) {
            return true;
        }
    }
    false
}

pub fn calculate_sha256_hash(file_path: &str) -> std::io::Result<String> {
    log::info!("Hashing {file_path}");
    let mut context = Context::new(&SHA256);
    let mut file = std::fs::File::open(file_path)?;

    let mut buffer = [0u8; 4096];
    loop {
        let n = file.read(&mut buffer)?;
        if n == 0 {
            break;
        }
        context.update(&buffer[..n]);
    }

    let digest = context.finish();
    Ok(hex::encode(digest.as_ref()))
}
