use std::path::{Path, PathBuf};
pub trait PathGrants {
fn normalize_existing_file(&self, path: &str) -> Result<PathBuf, String>;
fn path_to_string(&self, path: &Path) -> String;
fn require_granted_normalized(&self, path: &Path, what: &str) -> Result<(), String>;
fn require_existing_file(&self, path: &str) -> Result<String, String>;
fn require_write_target(&self, path: &str) -> Result<String, String>;
fn record_write_target(&self, path: &Path) -> Result<(), String>;
fn grant_existing_file_path(&self, path: &Path) -> Result<String, String>;
fn grant_existing_files(&self, paths: &[PathBuf]) -> Vec<String> {
paths
.iter()
.filter_map(|p| self.grant_existing_file_path(p).ok())
.collect()
}
fn register_known_stored_path(&self, path: &str) -> Result<String, String>;
fn grant_stream_token(&self, display: &str) -> Result<String, String>;
fn revoke_path(&self, display: &str) -> Result<(), String>;
}
pub fn authorize_existing_for_read(path: &str, grants: &dyn PathGrants) -> Result<String, String> {
let normalized = grants.normalize_existing_file(path)?;
grants.require_granted_normalized(&normalized, "path")?;
Ok(grants.path_to_string(&normalized))
}