Skip to main content

oximedia_edit/edl/
validator.rs

1//! EDL validation.
2
3use super::{Edl, EdlResult};
4
5/// EDL validation report.
6#[derive(Debug, Clone, Default)]
7pub struct ValidationReport {
8    /// Validation errors.
9    pub errors: Vec<String>,
10    /// Validation warnings.
11    pub warnings: Vec<String>,
12}
13
14impl ValidationReport {
15    /// Returns `true` if there are no errors.
16    #[must_use]
17    pub fn is_valid(&self) -> bool {
18        self.errors.is_empty()
19    }
20}
21
22/// EDL validator.
23#[derive(Debug, Default)]
24pub struct EdlValidator;
25
26impl EdlValidator {
27    /// Create a new validator.
28    #[must_use]
29    pub fn new() -> Self {
30        Self
31    }
32
33    /// Validate an EDL and return a report.
34    pub fn validate(&self, edl: &Edl) -> EdlResult<ValidationReport> {
35        let mut report = ValidationReport::default();
36
37        if edl.title.is_empty() {
38            report.warnings.push("EDL has no title".to_string());
39        }
40
41        if edl.events.is_empty() {
42            report.warnings.push("EDL has no events".to_string());
43        }
44
45        // Check for duplicate event numbers
46        let mut seen = std::collections::HashSet::new();
47        for event in &edl.events {
48            if !seen.insert(event.number) {
49                report
50                    .errors
51                    .push(format!("Duplicate event number: {}", event.number));
52            }
53        }
54
55        Ok(report)
56    }
57}