//! Community sharing configuration.

use serde::Deserialize;

/// Community sharing configuration for anonymous pattern contribution.
///
/// When enabled, Aphoria anonymizes scan observations and contributes them
/// to a central corpus. This allows community consensus to adjust default
/// thresholds over time.
///
/// # Privacy Model
///
/// - Project names are wildcarded: `code://rust/myapp/tls` → `code://rust/*/tls`
/// - File paths, line numbers, and matched text are NEVER shared
/// - Timestamps are rounded to the nearest hour for k-anonymity
/// - Server receives project_hash (not project_id)
///
/// # Example
///
/// ```toml
/// [community]
/// enabled = true
/// anonymize = true
/// exclude = ["vendor://acme/internal/*"]
/// min_confidence = 0.9
/// ```
#[derive(Debug, Clone, Deserialize)]
#[serde(default)]
pub struct CommunityConfig {
    /// Enable community sharing (opt-in only, default: false).
    ///
    /// CRITICAL: This defaults to false. Users must explicitly opt-in
    /// to share their scan patterns with the community.
    pub enabled: bool,

    /// Strip file/line/matched_text from shared observations (default: true).
    ///
    /// CRITICAL: This defaults to true. When enabled, the anon_hash is
    /// computed from (subject, predicate, value) only, excluding any
    /// information that could identify the source location.
    pub anonymize: bool,

    /// Concept paths to exclude from sharing (glob patterns).
    ///
    /// Useful for excluding internal/proprietary concepts:
    /// - `"vendor://acme/internal/*"` - exclude all internal vendor paths
    /// - `"code://*/secrets/*"` - exclude secrets-related concepts
    pub exclude: Vec<String>,

    /// Concept paths to include (whitelist, empty = all).
    ///
    /// If non-empty, only paths matching these patterns are shared.
    /// This is useful for limiting sharing to specific domains:
    /// - `["code://rust/"]` - only share Rust observations
    /// - `["code://*/tls/", "code://*/jwt/"]` - only share TLS and JWT patterns
    pub include: Vec<String>,

    /// Minimum confidence to share (default: 0.8).
    ///
    /// Observations with confidence below this threshold are not shared.
    /// Higher values reduce noise in the community corpus.
    pub min_confidence: f32,
}

impl CommunityConfig {
    /// Returns true if community sharing is enabled.
    pub fn is_enabled(&self) -> bool {
        self.enabled
    }
}
