//! Report wire types.

use serde::Serialize;
use shakrs_json_parser::Waiver;

/// The report document.
#[derive(Debug, Clone, Serialize)]
pub struct Report {
    pub version: u32,
    pub command: String,
    pub status: String,
    pub workspace: String,
    pub findings: Vec<Finding>,
    pub waived: Vec<WaivedFinding>,
    pub written: Vec<String>,
    pub skipped: Vec<String>,
    pub scaffolded: bool,
    pub validation_command_failures: Vec<ValidationCommandFailure>,
    pub reason: Option<String>,
    pub summary: Summary,
}

/// One failed adapter validation command.
#[derive(Debug, Clone, Serialize)]
pub struct ValidationCommandFailure {
    pub adapter_id: String,
    pub command_id: String,
    pub command: String,
    pub exit_code: Option<i32>,
    pub stdout: String,
    pub stderr: String,
}

/// One finding as it appears in the report.
#[derive(Debug, Clone, Serialize)]
pub struct Finding {
    pub key: String,
    pub subject: String,
    pub selector: Option<String>,
    pub severity: String,
    pub message: String,
    pub current: Option<String>,
    pub expected: Option<String>,
    pub policies: Vec<String>,
    #[serde(skip)]
    pub waivable: bool,
}

/// A finding paired with the waiver that suppressed it.
#[derive(Debug, Clone, Serialize)]
pub struct WaivedFinding {
    pub finding: Finding,
    pub waiver: Waiver,
}

/// Roll-up counts and the exit code.
#[derive(Debug, Clone, Copy, Serialize)]
pub struct Summary {
    pub findings: usize,
    pub waived: usize,
    pub exit_code: i32,
}
