webvh-watcher 0.10.1

WebVH Watcher, read-only DID mirror service
//! Health check diagnostic for `webvh-watcher health`.

use std::error::Error;
use std::path::PathBuf;

use did_hosting_common::server::health;

use crate::config::AppConfig;

pub async fn run_health(config_path: Option<PathBuf>) -> Result<(), Box<dyn Error>> {
    health::header("webvh-watcher", env!("CARGO_PKG_VERSION"));

    // ── Configuration ──────────────────────────────────────────────
    let config = match AppConfig::load(config_path) {
        Ok(c) => {
            health::section("Configuration");
            health::check_config_loaded(&c.config_path);
            let listen = format!("{}:{}", c.server.host, c.server.port);
            health::pass(&format!("Listen address: {listen}"));
            health::check_value("server_did", &c.server_did);
            health::check_value("mediator_did", &c.mediator_did);
            health::info_msg(&format!("Sync sources: {}", c.sync.source_dids.len()));
            Some(c)
        }
        Err(e) => {
            health::section("Configuration");
            health::fail(&format!("Config load failed: {e}"));
            None
        }
    };

    // ── Compile Features ───────────────────────────────────────────
    health::section("Compile Features");
    health::print_feature("store-fjall", cfg!(feature = "store-fjall"));
    health::print_feature("store-redis", cfg!(feature = "store-redis"));
    health::print_feature("store-dynamodb", cfg!(feature = "store-dynamodb"));
    health::print_feature("store-firestore", cfg!(feature = "store-firestore"));
    health::print_feature("store-cosmosdb", cfg!(feature = "store-cosmosdb"));

    let config = match config {
        Some(c) => c,
        None => {
            eprintln!();
            return Ok(());
        }
    };

    // ── Secrets ────────────────────────────────────────────────────
    health::section("Secrets");
    health::check_secrets(&config.secrets, &config.config_path).await;

    // ── Store ──────────────────────────────────────────────────────
    health::section("Store");
    health::check_store(&config.store).await;

    if let Some(ref did) = config.server_did {
        health::section("DID Resolution");
        health::check_did_resolution("Watcher DID resolves", did).await;
    }

    eprintln!();
    Ok(())
}