agent_migrate_adapters/
inventory.rs1use std::path::{Path, PathBuf};
2
3use agent_migrate_core::{AgentKind, BundleRelativePath, FileKind, Scope};
4use serde::Serialize;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
7#[serde(rename_all = "snake_case")]
8pub enum ResourceClass {
9 Migratable,
10 MetadataOnly,
11 Excluded,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
15pub struct ResourceEntry {
16 pub logical_path: String,
17 pub class: ResourceClass,
18 pub kind: Option<FileKind>,
19 pub reason: String,
20 pub bundle_path: Option<BundleRelativePath>,
21 #[serde(skip)]
22 source_path: Option<PathBuf>,
23}
24
25#[derive(Debug)]
26pub(crate) struct MigratableLocation {
27 pub logical: String,
28 pub source: PathBuf,
29 pub bundle: BundleRelativePath,
30}
31
32impl ResourceEntry {
33 #[must_use]
34 pub(crate) fn migratable(location: MigratableLocation, kind: FileKind) -> Self {
35 Self {
36 logical_path: location.logical,
37 class: ResourceClass::Migratable,
38 kind: Some(kind),
39 reason: "supported adapter resource".to_owned(),
40 bundle_path: Some(location.bundle),
41 source_path: Some(location.source),
42 }
43 }
44
45 #[must_use]
46 pub(crate) fn protected(class: ResourceClass, index: usize, reason: &str) -> Self {
47 Self {
48 logical_path: format!("<redacted:{index}>"),
49 class,
50 kind: None,
51 reason: reason.to_owned(),
52 bundle_path: None,
53 source_path: None,
54 }
55 }
56
57 #[must_use]
58 pub(crate) fn source_path(&self) -> Option<&Path> {
59 self.source_path.as_deref()
60 }
61}
62
63#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
64pub struct Inventory {
65 pub agent: AgentKind,
66 pub scope: Scope,
67 pub entries: Vec<ResourceEntry>,
68}
69
70impl Inventory {
71 #[must_use]
72 pub const fn new(agent: AgentKind, scope: Scope, entries: Vec<ResourceEntry>) -> Self {
73 Self {
74 agent,
75 scope,
76 entries,
77 }
78 }
79
80 #[must_use]
81 pub fn count(&self, class: ResourceClass) -> usize {
82 self.entries
83 .iter()
84 .filter(|entry| entry.class == class)
85 .count()
86 }
87}