use lazy_static::lazy_static;
use prometheus::{
    register_counter_vec, register_histogram_vec, CounterVec, HistogramVec, Registry,
};

lazy_static! {
    pub static ref A2A_TASKS_TOTAL: CounterVec = register_counter_vec!(
        "vapora_a2a_tasks_total",
        "Total A2A tasks by status",
        &["status"] // waiting, working, completed, failed
    )
    .expect("Failed to register A2A_TASKS_TOTAL");
    pub static ref A2A_TASK_DURATION: HistogramVec = register_histogram_vec!(
        "vapora_a2a_task_duration_seconds",
        "A2A task execution duration",
        &["status"], // completed, failed
        vec![0.1, 0.5, 1.0, 5.0, 10.0, 30.0, 60.0, 120.0, 300.0]
    )
    .expect("Failed to register A2A_TASK_DURATION");
    pub static ref A2A_NATS_MESSAGES: CounterVec = register_counter_vec!(
        "vapora_a2a_nats_messages_total",
        "NATS messages received",
        &["subject", "result"] // subject: completed/failed, result: success/error
    )
    .expect("Failed to register A2A_NATS_MESSAGES");
    pub static ref A2A_DB_OPERATIONS: CounterVec = register_counter_vec!(
        "vapora_a2a_db_operations_total",
        "Database operations",
        &["operation", "result"] // operation: create/update/query, result: success/error
    )
    .expect("Failed to register A2A_DB_OPERATIONS");
    pub static ref A2A_COORDINATOR_ASSIGNMENTS: CounterVec = register_counter_vec!(
        "vapora_a2a_coordinator_assignments_total",
        "Tasks assigned to coordinator",
        &["skill", "result"] // skill: developer/architect/etc, result: success/error
    )
    .expect("Failed to register A2A_COORDINATOR_ASSIGNMENTS");
}

/// Register all A2A metrics with a custom registry (optional)
pub fn register_metrics(registry: &Registry) -> Result<(), prometheus::Error> {
    registry.register(Box::new(A2A_TASKS_TOTAL.clone()))?;
    registry.register(Box::new(A2A_TASK_DURATION.clone()))?;
    registry.register(Box::new(A2A_NATS_MESSAGES.clone()))?;
    registry.register(Box::new(A2A_DB_OPERATIONS.clone()))?;
    registry.register(Box::new(A2A_COORDINATOR_ASSIGNMENTS.clone()))?;
    Ok(())
}
