Skip to main content

capsule_core/import/
scan.rs

1use std::path::PathBuf;
2
3use crate::domain::{DetectionMethod, MemberRole, StackType};
4use crate::metadata::AssetType;
5
6/// One logical "unit" of import — either a standalone file or a set of
7/// related files (RAW+JPEG pair, Live Photo HEIC+MOV, etc.).
8#[derive(Debug, Clone)]
9pub struct ImportCandidate {
10    /// All source file paths belonging to this candidate.
11    pub source_paths: Vec<PathBuf>,
12    /// Detected media type (of the primary member).
13    pub detected_type: AssetType,
14    /// Stack type, present when the candidate forms a multi-file stack.
15    pub stack_type: Option<StackType>,
16    /// How the stack relationship was detected.
17    pub detection_method: Option<DetectionMethod>,
18    /// Unique key for this stack group within its source directory.
19    pub detection_key: Option<String>,
20    /// Ordered list of (path, member role) for every file in the candidate.
21    pub members: Vec<(PathBuf, MemberRole)>,
22}
23
24impl ImportCandidate {
25    /// Returns the primary path (first `Primary` role member, or `source_paths[0]`).
26    pub fn primary_path(&self) -> &PathBuf {
27        self.members
28            .iter()
29            .find(|(_, r)| *r == MemberRole::Primary)
30            .map_or(&self.source_paths[0], |(p, _)| p)
31    }
32}
33
34/// Output of Phase 1 (scan).
35#[derive(Debug, Default)]
36pub struct ScanResult {
37    pub candidates: Vec<ImportCandidate>,
38}
39
40impl ScanResult {
41    pub fn total_files(&self) -> usize {
42        self.candidates.iter().map(|c| c.source_paths.len()).sum()
43    }
44}