use chrono::Utc;
use super::FileChange;
impl FileChange {
pub fn read(path: &str, line_range: Option<(u32, u32)>) -> Self {
Self {
path: path.to_string(),
operation: "read".to_string(),
timestamp: Utc::now(),
size_bytes: None,
line_range,
diff: None,
}
}
pub fn create(path: &str, content: &str) -> Self {
Self {
path: path.to_string(),
operation: "create".to_string(),
timestamp: Utc::now(),
size_bytes: Some(content.len() as u64),
line_range: None,
diff: None,
}
}
pub fn modify(
path: &str,
old_content: &str,
new_content: &str,
line_range: Option<(u32, u32)>,
) -> Self {
Self {
path: path.to_string(),
operation: "modify".to_string(),
timestamp: Utc::now(),
size_bytes: Some(new_content.len() as u64),
line_range,
diff: Some(format!(
"-{} bytes +{} bytes",
old_content.len(),
new_content.len()
)),
}
}
pub fn modify_with_diff(
path: &str,
diff: &str,
new_size: usize,
line_range: Option<(u32, u32)>,
) -> Self {
Self {
path: path.to_string(),
operation: "modify".to_string(),
timestamp: Utc::now(),
size_bytes: Some(new_size as u64),
line_range,
diff: Some(diff.to_string()),
}
}
}