use super::super::types::{OrgArchetype, OrgSuiteError, TransitionTrigger};
use super::condition::{ConditionContext, TransitionCondition};
use super::converter::OrgConverter;
use serde_json::json;
pub struct HolacracyToHierarchyConverter;
impl OrgConverter for HolacracyToHierarchyConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Holacracy
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Hierarchy
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "hierarchy",
"converted_from": "holacracy",
"departments": source_data.get("circles").unwrap_or(&json!([])),
"command_queue": source_data.get("task_pool").unwrap_or(&json!([])),
"positions": source_data.get("roles").unwrap_or(&json!([])),
"note": "Converted from self-organizing circles to hierarchical departments"
});
Ok(converted)
}
}
pub struct HierarchyToSocialConverter;
impl OrgConverter for HierarchyToSocialConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Hierarchy
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Social
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "social",
"converted_from": "hierarchy",
"network_edges": source_data.get("relationships").unwrap_or(&json!([])),
"influence_scores": source_data.get("ranks").unwrap_or(&json!({})),
"bribery_costs": source_data.get("tax_rate").unwrap_or(&json!(0.0)),
"note": "Converted from hierarchical command to social influence network"
});
Ok(converted)
}
}
pub struct SocialToCultureConverter;
impl OrgConverter for SocialToCultureConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Social
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Culture
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "culture",
"converted_from": "social",
"dogmas": source_data.get("factions").unwrap_or(&json!([])),
"fervor": source_data.get("social_capital").unwrap_or(&json!(0.0)),
"charismatic_leaders": source_data.get("high_centrality_members").unwrap_or(&json!([])),
"note": "Converted from social network to cultural meme organization"
});
Ok(converted)
}
}
pub struct HolacracyToSocialConverter;
impl OrgConverter for HolacracyToSocialConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Holacracy
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Social
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "social",
"converted_from": "holacracy",
"network_edges": source_data.get("collaborations").unwrap_or(&json!([])),
"clusters": source_data.get("circles").unwrap_or(&json!([])),
"social_capital": source_data.get("skill_scores").unwrap_or(&json!({})),
"note": "Converted from task-based collaboration to social influence network"
});
Ok(converted)
}
}
pub struct HolacracyToCultureConverter;
impl OrgConverter for HolacracyToCultureConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Holacracy
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Culture
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "culture",
"converted_from": "holacracy",
"dogmas": source_data.get("shared_purpose").unwrap_or(&json!([])),
"zealots": source_data.get("high_performers").unwrap_or(&json!([])),
"rituals": source_data.get("circle_practices").unwrap_or(&json!([])),
"note": "Converted from self-organizing purpose to cultural zealotry"
});
Ok(converted)
}
}
pub struct HierarchyToHolacracyConverter;
impl OrgConverter for HierarchyToHolacracyConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Hierarchy
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Holacracy
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "holacracy",
"converted_from": "hierarchy",
"circles": source_data.get("departments").unwrap_or(&json!([])),
"roles": source_data.get("positions").unwrap_or(&json!([])),
"task_pool": source_data.get("command_queue").unwrap_or(&json!([])),
"note": "Converted from hierarchical departments to self-organizing circles"
});
Ok(converted)
}
}
pub struct HierarchyToCultureConverter;
impl OrgConverter for HierarchyToCultureConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Hierarchy
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Culture
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "culture",
"converted_from": "hierarchy",
"divine_leader": source_data.get("top_leader").unwrap_or(&json!(null)),
"commandments": source_data.get("orders").unwrap_or(&json!([])),
"devotion_level": source_data.get("loyalty_average").unwrap_or(&json!(0.0)),
"note": "Converted from hierarchical authority to personality cult"
});
Ok(converted)
}
}
pub struct SocialToHolacracyConverter;
impl OrgConverter for SocialToHolacracyConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Social
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Holacracy
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "holacracy",
"converted_from": "social",
"circles": source_data.get("clusters").unwrap_or(&json!([])),
"circle_leads": source_data.get("influential_members").unwrap_or(&json!([])),
"tasks": source_data.get("shared_goals").unwrap_or(&json!([])),
"note": "Converted from social network to purposeful self-organization"
});
Ok(converted)
}
}
pub struct SocialToHierarchyConverter;
impl OrgConverter for SocialToHierarchyConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Social
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Hierarchy
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "hierarchy",
"converted_from": "social",
"leaders": source_data.get("high_influence").unwrap_or(&json!([])),
"reporting_structure": source_data.get("network_edges").unwrap_or(&json!([])),
"formal_obligations": source_data.get("favors_owed").unwrap_or(&json!([])),
"note": "Converted from informal influence network to formal hierarchy"
});
Ok(converted)
}
}
pub struct CultureToHolacracyConverter;
impl OrgConverter for CultureToHolacracyConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Culture
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Holacracy
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "holacracy",
"converted_from": "culture",
"principles": source_data.get("dogmas").unwrap_or(&json!([])),
"practices": source_data.get("rituals").unwrap_or(&json!([])),
"members": source_data.get("zealots").unwrap_or(&json!([])),
"note": "Converted from cultural dogma to rational self-organization"
});
Ok(converted)
}
}
pub struct CultureToHierarchyConverter;
impl OrgConverter for CultureToHierarchyConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Culture
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Hierarchy
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "hierarchy",
"converted_from": "culture",
"formal_leader": source_data.get("charismatic_leader").unwrap_or(&json!(null)),
"executive_committee": source_data.get("inner_circle").unwrap_or(&json!([])),
"policies": source_data.get("dogmas").unwrap_or(&json!([])),
"note": "Converted from cultural movement to institutional hierarchy"
});
Ok(converted)
}
}
pub struct CultureToSocialConverter;
impl OrgConverter for CultureToSocialConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Culture
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Social
}
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError> {
let converted = json!({
"archetype": "social",
"converted_from": "culture",
"network_nodes": source_data.get("members").unwrap_or(&json!([])),
"bonds": source_data.get("shared_beliefs").unwrap_or(&json!([])),
"influence_map": source_data.get("charisma_scores").unwrap_or(&json!({})),
"note": "Converted from cultural cult to informal social network"
});
Ok(converted)
}
}
#[derive(Debug, Clone)]
pub struct ScalingCondition {
pub threshold: usize,
pub from_archetype: OrgArchetype,
pub to_archetype: OrgArchetype,
}
impl ScalingCondition {
pub fn new(threshold: usize, from: OrgArchetype, to: OrgArchetype) -> Self {
Self {
threshold,
from_archetype: from,
to_archetype: to,
}
}
}
impl TransitionCondition for ScalingCondition {
fn evaluate(
&self,
_faction_id: &str,
current: OrgArchetype,
context: &ConditionContext,
) -> Option<TransitionTrigger> {
if current == self.from_archetype && context.member_count >= self.threshold {
Some(TransitionTrigger::Scaling {
from: self.from_archetype,
to: self.to_archetype,
member_count: context.member_count,
})
} else {
None
}
}
}
#[derive(Debug, Clone)]
pub struct DecayCondition {
pub threshold: f32,
pub from_archetype: OrgArchetype,
pub to_archetype: OrgArchetype,
}
impl DecayCondition {
pub fn new(threshold: f32, from: OrgArchetype, to: OrgArchetype) -> Self {
Self {
threshold,
from_archetype: from,
to_archetype: to,
}
}
}
impl TransitionCondition for DecayCondition {
fn evaluate(
&self,
_faction_id: &str,
current: OrgArchetype,
context: &ConditionContext,
) -> Option<TransitionTrigger> {
if current == self.from_archetype && context.corruption_level >= self.threshold {
Some(TransitionTrigger::Decay {
from: self.from_archetype,
to: self.to_archetype,
corruption_level: context.corruption_level,
})
} else {
None
}
}
}
#[derive(Debug, Clone)]
pub struct RadicalizationCondition {
pub threshold: f32,
pub from_archetype: OrgArchetype,
pub to_archetype: OrgArchetype,
}
impl RadicalizationCondition {
pub fn new(threshold: f32, from: OrgArchetype, to: OrgArchetype) -> Self {
Self {
threshold,
from_archetype: from,
to_archetype: to,
}
}
}
impl TransitionCondition for RadicalizationCondition {
fn evaluate(
&self,
_faction_id: &str,
current: OrgArchetype,
context: &ConditionContext,
) -> Option<TransitionTrigger> {
if current == self.from_archetype && context.fervor_level >= self.threshold {
Some(TransitionTrigger::Radicalization {
from: self.from_archetype,
to: self.to_archetype,
fervor_level: context.fervor_level,
})
} else {
None
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_holacracy_to_hierarchy_converter() {
let converter = HolacracyToHierarchyConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Holacracy);
assert_eq!(converter.target_archetype(), OrgArchetype::Hierarchy);
let source = json!({
"circles": ["engineering", "sales"],
"task_pool": ["task1", "task2"],
"roles": ["developer", "manager"]
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "hierarchy");
assert_eq!(result["converted_from"], "holacracy");
}
#[test]
fn test_hierarchy_to_social_converter() {
let converter = HierarchyToSocialConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Hierarchy);
assert_eq!(converter.target_archetype(), OrgArchetype::Social);
let source = json!({
"relationships": [{"from": "A", "to": "B"}],
"ranks": {"A": 5, "B": 3}
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "social");
}
#[test]
fn test_social_to_culture_converter() {
let converter = SocialToCultureConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Social);
assert_eq!(converter.target_archetype(), OrgArchetype::Culture);
let source = json!({
"factions": ["faction_a", "faction_b"],
"social_capital": 0.9
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "culture");
assert_eq!(result["fervor"], 0.9);
}
#[test]
fn test_holacracy_to_social_converter() {
let converter = HolacracyToSocialConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Holacracy);
assert_eq!(converter.target_archetype(), OrgArchetype::Social);
let source = json!({
"collaborations": [{"a": "b"}],
"circles": ["circle1"],
"skill_scores": {"member1": 0.9}
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "social");
assert_eq!(result["converted_from"], "holacracy");
}
#[test]
fn test_holacracy_to_culture_converter() {
let converter = HolacracyToCultureConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Holacracy);
assert_eq!(converter.target_archetype(), OrgArchetype::Culture);
let source = json!({
"shared_purpose": ["mission1"],
"high_performers": ["member1", "member2"],
"circle_practices": ["daily_standup"]
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "culture");
assert_eq!(result["converted_from"], "holacracy");
}
#[test]
fn test_hierarchy_to_holacracy_converter() {
let converter = HierarchyToHolacracyConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Hierarchy);
assert_eq!(converter.target_archetype(), OrgArchetype::Holacracy);
let source = json!({
"departments": ["engineering", "sales"],
"positions": ["dev", "manager"],
"command_queue": ["task1"]
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "holacracy");
assert_eq!(result["converted_from"], "hierarchy");
}
#[test]
fn test_hierarchy_to_culture_converter() {
let converter = HierarchyToCultureConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Hierarchy);
assert_eq!(converter.target_archetype(), OrgArchetype::Culture);
let source = json!({
"top_leader": "supreme_leader",
"orders": ["order1", "order2"],
"loyalty_average": 0.95
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "culture");
assert_eq!(result["converted_from"], "hierarchy");
assert_eq!(result["devotion_level"], 0.95);
}
#[test]
fn test_social_to_holacracy_converter() {
let converter = SocialToHolacracyConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Social);
assert_eq!(converter.target_archetype(), OrgArchetype::Holacracy);
let source = json!({
"clusters": ["cluster1", "cluster2"],
"influential_members": ["leader1"],
"shared_goals": ["goal1"]
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "holacracy");
assert_eq!(result["converted_from"], "social");
}
#[test]
fn test_social_to_hierarchy_converter() {
let converter = SocialToHierarchyConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Social);
assert_eq!(converter.target_archetype(), OrgArchetype::Hierarchy);
let source = json!({
"high_influence": ["influencer1"],
"network_edges": [{"from": "A", "to": "B"}],
"favors_owed": ["favor1"]
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "hierarchy");
assert_eq!(result["converted_from"], "social");
}
#[test]
fn test_culture_to_holacracy_converter() {
let converter = CultureToHolacracyConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Culture);
assert_eq!(converter.target_archetype(), OrgArchetype::Holacracy);
let source = json!({
"dogmas": ["belief1", "belief2"],
"rituals": ["ritual1"],
"zealots": ["member1", "member2"]
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "holacracy");
assert_eq!(result["converted_from"], "culture");
}
#[test]
fn test_culture_to_hierarchy_converter() {
let converter = CultureToHierarchyConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Culture);
assert_eq!(converter.target_archetype(), OrgArchetype::Hierarchy);
let source = json!({
"charismatic_leader": "leader1",
"inner_circle": ["member1", "member2"],
"dogmas": ["dogma1"]
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "hierarchy");
assert_eq!(result["converted_from"], "culture");
}
#[test]
fn test_culture_to_social_converter() {
let converter = CultureToSocialConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Culture);
assert_eq!(converter.target_archetype(), OrgArchetype::Social);
let source = json!({
"members": ["member1", "member2"],
"shared_beliefs": ["belief1"],
"charisma_scores": {"member1": 0.8}
});
let result = converter.convert(&source).unwrap();
assert_eq!(result["archetype"], "social");
assert_eq!(result["converted_from"], "culture");
}
#[test]
fn test_scaling_condition_triggered() {
let condition = ScalingCondition::new(50, OrgArchetype::Holacracy, OrgArchetype::Hierarchy);
let context = ConditionContext {
member_count: 60,
..Default::default()
};
let result = condition.evaluate("test", OrgArchetype::Holacracy, &context);
assert!(result.is_some());
match result.unwrap() {
TransitionTrigger::Scaling { member_count, .. } => {
assert_eq!(member_count, 60);
}
_ => panic!("Expected Scaling trigger"),
}
}
#[test]
fn test_scaling_condition_not_triggered() {
let condition = ScalingCondition::new(50, OrgArchetype::Holacracy, OrgArchetype::Hierarchy);
let context = ConditionContext {
member_count: 30,
..Default::default()
};
let result = condition.evaluate("test", OrgArchetype::Holacracy, &context);
assert!(result.is_none());
}
#[test]
fn test_decay_condition_triggered() {
let condition = DecayCondition::new(0.8, OrgArchetype::Hierarchy, OrgArchetype::Social);
let context = ConditionContext {
corruption_level: 0.9,
..Default::default()
};
let result = condition.evaluate("test", OrgArchetype::Hierarchy, &context);
assert!(result.is_some());
}
#[test]
fn test_radicalization_condition_triggered() {
let condition =
RadicalizationCondition::new(0.9, OrgArchetype::Social, OrgArchetype::Culture);
let context = ConditionContext {
fervor_level: 0.95,
..Default::default()
};
let result = condition.evaluate("test", OrgArchetype::Social, &context);
assert!(result.is_some());
match result.unwrap() {
TransitionTrigger::Radicalization { fervor_level, .. } => {
assert_eq!(fervor_level, 0.95);
}
_ => panic!("Expected Radicalization trigger"),
}
}
#[test]
fn test_conditions_wrong_archetype() {
let scaling = ScalingCondition::new(50, OrgArchetype::Holacracy, OrgArchetype::Hierarchy);
let decay = DecayCondition::new(0.8, OrgArchetype::Hierarchy, OrgArchetype::Social);
let context = ConditionContext {
member_count: 100,
corruption_level: 0.9,
..Default::default()
};
assert!(scaling
.evaluate("test", OrgArchetype::Hierarchy, &context)
.is_none());
assert!(decay
.evaluate("test", OrgArchetype::Holacracy, &context)
.is_none());
}
}