//! Chain watcher configuration

use newton_core::config::ConfigLoader;
use serde::{Deserialize, Serialize};

/// chain watcher service configuration
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct ChainWatcherConfig {
    /// redis url for the seen-tasks SET (shared with gateway)
    pub redis_url: String,
    /// gateway watcher endpoint url (e.g., `http://gateway:9001/watcher`)
    pub gateway_watcher_url: String,
    /// max retries for gateway HTTP calls
    pub max_retries: u32,
    /// prometheus metrics port (default: 9097)
    pub metrics_port: u16,
    /// shared secret for HMAC-signing watcher events (Octane #10).
    /// Hex-encoded; 32 bytes recommended. When `None`, requests are sent
    /// unsigned and the gateway must also have no PSK configured.
    #[serde(default)]
    pub gateway_psk: Option<String>,
}

impl ConfigLoader for ChainWatcherConfig {
    const FILE_NAME: &'static str = "chain-watcher";
    const ENV_PREFIX: &'static str = "CHAIN_WATCHER";
}

impl Default for ChainWatcherConfig {
    fn default() -> Self {
        Self {
            redis_url: "redis://127.0.0.1:6379".to_string(),
            gateway_watcher_url: "http://127.0.0.1:9001/watcher".to_string(),
            max_retries: 3,
            metrics_port: 9097,
            gateway_psk: None,
        }
    }
}
