pub use thirdpass_core::schema::{
    Priority, ReviewConfidence, ReviewScope, ReviewerDetails, SecuritySummary,
};

#[derive(
    Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, serde::Serialize, serde::Deserialize,
)]
pub struct ReviewTarget {
    pub file_path: std::path::PathBuf,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub file_hash: Option<thirdpass_core::schema::FileHash>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub agent_summary: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub security_summary: Option<SecuritySummary>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub confidence: Option<ReviewConfidence>,
    pub comments: std::collections::BTreeSet<crate::review::comment::Comment>,
}

#[derive(Debug, Clone, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Review {
    #[serde(skip)]
    pub id: crate::common::index::ID,
    #[serde(skip)]
    pub peer: crate::peer::Peer,
    pub package: crate::package::Package,
    pub targets: Vec<ReviewTarget>,
    #[serde(default)]
    pub reviewer_details: ReviewerDetails,
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub agent_summary: String,
    #[serde(default)]
    pub overall_security_summary: SecuritySummary,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub overall_security_confidence: Option<ReviewConfidence>,
}

impl Ord for Review {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (&self.peer, &self.package, &self.targets, &self.id).cmp(&(
            &other.peer,
            &other.package,
            &other.targets,
            &other.id,
        ))
    }
}

impl PartialOrd for Review {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
