/*
 * Artifact Keeper API
 *
 * REST API for Artifact Keeper, an open-source universal artifact registry. Covers user management, repositories, artifacts, search, security scanning, SBOM, dependency tracking, SSO, analytics, monitoring, telemetry, lifecycle policies, plugins, edge nodes, migration, and administration. Format-specific protocol endpoints (npm, PyPI, Maven, Docker/OCI, etc.) are not included; those follow their respective upstream specifications.
 *
 * The version of the OpenAPI document: 1.0.0-a2
 * 
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct CveHistoryEntry {
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    #[serde(rename = "artifact_id")]
    pub artifact_id: uuid::Uuid,
    /// SBOM in which the CVE was detected.
    #[serde(rename = "sbom_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub sbom_id: Option<Option<uuid::Uuid>>,
    /// SBOM component associated with the CVE.
    #[serde(rename = "component_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub component_id: Option<Option<uuid::Uuid>>,
    /// Security scan result that surfaced this CVE.
    #[serde(rename = "scan_result_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub scan_result_id: Option<Option<uuid::Uuid>>,
    /// CVE identifier (e.g. CVE-2024-1234).
    #[serde(rename = "cve_id")]
    pub cve_id: String,
    /// Name of the affected software component.
    #[serde(rename = "affected_component", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub affected_component: Option<Option<String>>,
    /// Version range affected by the CVE.
    #[serde(rename = "affected_version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub affected_version: Option<Option<String>>,
    /// Earliest version that contains the fix.
    #[serde(rename = "fixed_version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub fixed_version: Option<Option<String>>,
    /// Severity level (e.g. critical, high, medium, low).
    #[serde(rename = "severity", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub severity: Option<Option<String>>,
    /// CVSS score (0.0 - 10.0).
    #[serde(rename = "cvss_score", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub cvss_score: Option<Option<f64>>,
    /// Date the CVE was publicly disclosed.
    #[serde(rename = "cve_published_at", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub cve_published_at: Option<Option<String>>,
    /// Timestamp when this CVE was first detected for the artifact.
    #[serde(rename = "first_detected_at")]
    pub first_detected_at: String,
    /// Timestamp of the most recent scan that detected this CVE.
    #[serde(rename = "last_detected_at")]
    pub last_detected_at: String,
    /// Current triage status (e.g. open, acknowledged, mitigated, false_positive).
    #[serde(rename = "status")]
    pub status: String,
    /// User who acknowledged or triaged this CVE.
    #[serde(rename = "acknowledged_by", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub acknowledged_by: Option<Option<uuid::Uuid>>,
    /// Timestamp when the CVE was acknowledged.
    #[serde(rename = "acknowledged_at", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub acknowledged_at: Option<Option<String>>,
    /// Reason provided when the CVE status was changed.
    #[serde(rename = "acknowledged_reason", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub acknowledged_reason: Option<Option<String>>,
    #[serde(rename = "created_at")]
    pub created_at: String,
    #[serde(rename = "updated_at")]
    pub updated_at: String,
}

impl CveHistoryEntry {
    pub fn new(id: uuid::Uuid, artifact_id: uuid::Uuid, cve_id: String, first_detected_at: String, last_detected_at: String, status: String, created_at: String, updated_at: String) -> CveHistoryEntry {
        CveHistoryEntry {
            id,
            artifact_id,
            sbom_id: None,
            component_id: None,
            scan_result_id: None,
            cve_id,
            affected_component: None,
            affected_version: None,
            fixed_version: None,
            severity: None,
            cvss_score: None,
            cve_published_at: None,
            first_detected_at,
            last_detected_at,
            status,
            acknowledged_by: None,
            acknowledged_at: None,
            acknowledged_reason: None,
            created_at,
            updated_at,
        }
    }
}

