use async_trait::async_trait;
use super::types::{CentralityMetrics, Faction, FactionId, MemberId, PoliticalAction};
use crate::context::ResourceContext;
#[async_trait]
pub trait SocialHook: Send + Sync {
async fn on_centrality_calculated(
&self,
_faction_id: &FactionId,
_member_id: &MemberId,
_metrics: &CentralityMetrics,
_resources: &mut ResourceContext,
) {
}
async fn on_shadow_leader_detected(
&self,
_faction_id: &FactionId,
_member_id: &MemberId,
_influence_score: f32,
_resources: &mut ResourceContext,
) {
}
async fn on_political_action_requested(
&self,
_faction_id: &FactionId,
_actor_id: &MemberId,
_action: &PoliticalAction,
_resources: &mut ResourceContext,
) -> Result<(), String> {
Ok(())
}
async fn on_political_action_executed(
&self,
_faction_id: &FactionId,
_actor_id: &MemberId,
_action: &PoliticalAction,
_success: bool,
_resources: &mut ResourceContext,
) {
}
async fn on_favor_exchanged(
&self,
_faction_id: &FactionId,
_grantor: &MemberId,
_recipient: &MemberId,
_favor_value: f32,
_resources: &mut ResourceContext,
) {
}
async fn on_secret_shared(
&self,
_faction_id: &FactionId,
_sharer: &MemberId,
_receiver: &MemberId,
_secret_id: &str,
_sensitivity: f32,
_resources: &mut ResourceContext,
) {
}
#[allow(clippy::too_many_arguments)]
async fn on_gossip_spread(
&self,
_faction_id: &FactionId,
_spreader: &MemberId,
_about: &MemberId,
_content: &str,
_is_positive: bool,
_reached_count: usize,
_resources: &mut ResourceContext,
) {
}
async fn on_faction_formed(
&self,
_org_faction_id: &FactionId,
_new_faction: &Faction,
_founding_members: &[MemberId],
_resources: &mut ResourceContext,
) {
}
async fn on_faction_split(
&self,
_org_faction_id: &FactionId,
_original_faction_id: &FactionId,
_new_faction_ids: &[FactionId],
_reason: &str,
_resources: &mut ResourceContext,
) {
}
async fn on_faction_merged(
&self,
_org_faction_id: &FactionId,
_merged_faction_id: &FactionId,
_source_faction_ids: &[FactionId],
_total_members: usize,
_resources: &mut ResourceContext,
) {
}
async fn on_trust_decayed(
&self,
_faction_id: &FactionId,
_from: &MemberId,
_to: &MemberId,
_new_strength: f32,
_resources: &mut ResourceContext,
) {
}
async fn on_favor_expired(
&self,
_faction_id: &FactionId,
_creditor: &MemberId,
_debtor: &MemberId,
_favor_value: f32,
_resources: &mut ResourceContext,
) {
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct DefaultSocialHook;
#[async_trait]
impl SocialHook for DefaultSocialHook {}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_default_hook() {
let hook = DefaultSocialHook;
let mut resources = ResourceContext::new();
hook.on_centrality_calculated(
&"faction1".to_string(),
&"member1".to_string(),
&CentralityMetrics::default(),
&mut resources,
)
.await;
hook.on_shadow_leader_detected(
&"faction1".to_string(),
&"kingmaker".to_string(),
0.85,
&mut resources,
)
.await;
let action = PoliticalAction::GrantFavor {
target: "member2".to_string(),
favor_value: 1.0,
};
let result = hook
.on_political_action_requested(
&"faction1".to_string(),
&"member1".to_string(),
&action,
&mut resources,
)
.await;
assert!(result.is_ok());
}
}