Skip to main content

agent_migrate_core/
compatibility.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4#[serde(tag = "state", rename_all = "snake_case")]
5pub enum Compatibility {
6    Exact,
7    Converted,
8    Bridged { requirement: String },
9    Lossy { reason: String },
10    PreservedUnavailable { reason: String },
11    Blocked { reason: String },
12}
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum ImportDecision {
16    Allowed,
17    NeedsLossyAcceptance,
18    BridgeUnavailable,
19    Blocked,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct ImportPolicy {
24    accept_lossy: bool,
25}
26
27impl ImportPolicy {
28    #[must_use]
29    pub const fn strict() -> Self {
30        Self {
31            accept_lossy: false,
32        }
33    }
34
35    #[must_use]
36    pub const fn accept_lossy() -> Self {
37        Self { accept_lossy: true }
38    }
39
40    #[must_use]
41    pub fn decide(self, compatibility: &Compatibility, bridge_healthy: bool) -> ImportDecision {
42        match compatibility {
43            Compatibility::Exact | Compatibility::Converted => ImportDecision::Allowed,
44            Compatibility::Bridged { .. } if bridge_healthy => ImportDecision::Allowed,
45            Compatibility::Bridged { .. } => ImportDecision::BridgeUnavailable,
46            Compatibility::Lossy { .. } | Compatibility::PreservedUnavailable { .. }
47                if self.accept_lossy =>
48            {
49                ImportDecision::Allowed
50            }
51            Compatibility::Lossy { .. } | Compatibility::PreservedUnavailable { .. } => {
52                ImportDecision::NeedsLossyAcceptance
53            }
54            Compatibility::Blocked { .. } => ImportDecision::Blocked,
55        }
56    }
57}