//! Session sharing abstraction
//!
//! The `SessionShare` trait abstracts bidirectional bridges between Dirigent
//! sessions and external communication systems (Matrix, Slack, etc.).
//!
//! A share attaches to a (connector_id, session_id) pair without taking
//! ownership of the session. Multiple shares can coexist on the same session.

use async_trait::async_trait;
use serde::{Deserialize, Serialize};

/// Unique identifier for a share instance.
pub type ShareId = String;

/// Summary info about an active share.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShareSummary {
    /// Share identifier (e.g., "matrix:connector-1:session-abc")
    pub id: ShareId,
    /// Connector this share is attached to
    pub connector_id: String,
    /// Session this share is attached to
    pub session_id: String,
    /// Backend type (e.g., "matrix", "slack")
    pub backend: String,
    /// Backend-specific destination (e.g., Matrix room ID)
    pub destination: String,
    /// Whether the share is currently active
    pub active: bool,
}

/// Trait for session share backends.
///
/// Implementors provide bidirectional bridging between a Dirigent session
/// and an external system. The trait is deliberately minimal — the concrete
/// implementation handles all backend-specific details.
///
/// # Design Notes
///
/// - Shares do NOT modify the Connector trait or require special connector support
/// - Shares use existing channels: `connector.subscribe()` for events,
///   `connector.command_tx()` for sending messages
/// - Multiple shares can be active on the same session simultaneously
#[async_trait]
pub trait SessionShare: Send + Sync {
    /// Get summary information about this share.
    fn summary(&self) -> ShareSummary;

    /// Check if the share is actively forwarding.
    fn is_active(&self) -> bool;

    /// Gracefully shut down this share.
    async fn shutdown(&self);
}
