/*
 * 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};

/// CrashReport : A recorded application crash event with diagnostic information.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct CrashReport {
    /// Unique identifier for the crash report.
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    /// Classification of the error (e.g. panic, segfault, oom).
    #[serde(rename = "error_type")]
    pub error_type: String,
    /// Human-readable error message captured at crash time.
    #[serde(rename = "error_message")]
    pub error_message: String,
    /// Full stack trace captured at the point of failure.
    #[serde(rename = "stack_trace", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub stack_trace: Option<Option<String>>,
    /// Application component or subsystem where the crash originated.
    #[serde(rename = "component")]
    pub component: String,
    /// Severity level of the crash (e.g. critical, error, warning).
    #[serde(rename = "severity")]
    pub severity: String,
    /// Application version string at the time of the crash.
    #[serde(rename = "app_version")]
    pub app_version: String,
    /// Operating system and platform information.
    #[serde(rename = "os_info", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub os_info: Option<Option<String>>,
    /// Application uptime in seconds before the crash occurred.
    #[serde(rename = "uptime_seconds", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub uptime_seconds: Option<Option<i32>>,
    /// Arbitrary key-value metadata providing additional crash context.
    #[serde(rename = "context")]
    pub context: serde_json::Value,
    /// Whether this crash report has been submitted to the telemetry service.
    #[serde(rename = "submitted")]
    pub submitted: bool,
    /// Timestamp when the crash report was submitted.
    #[serde(rename = "submitted_at", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub submitted_at: Option<Option<String>>,
    /// Error message if the most recent submission attempt failed.
    #[serde(rename = "submission_error", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub submission_error: Option<Option<String>>,
    /// Deduplicated signature derived from the error type and stack trace.
    #[serde(rename = "error_signature")]
    pub error_signature: String,
    /// Number of times this crash (by signature) has been observed.
    #[serde(rename = "occurrence_count")]
    pub occurrence_count: i32,
    /// Timestamp of the first occurrence of this crash signature.
    #[serde(rename = "first_seen_at")]
    pub first_seen_at: String,
    /// Timestamp of the most recent occurrence of this crash signature.
    #[serde(rename = "last_seen_at")]
    pub last_seen_at: String,
    /// Timestamp when this crash report record was created.
    #[serde(rename = "created_at")]
    pub created_at: String,
}

impl CrashReport {
    /// A recorded application crash event with diagnostic information.
    pub fn new(id: uuid::Uuid, error_type: String, error_message: String, component: String, severity: String, app_version: String, context: serde_json::Value, submitted: bool, error_signature: String, occurrence_count: i32, first_seen_at: String, last_seen_at: String, created_at: String) -> CrashReport {
        CrashReport {
            id,
            error_type,
            error_message,
            stack_trace: None,
            component,
            severity,
            app_version,
            os_info: None,
            uptime_seconds: None,
            context,
            submitted,
            submitted_at: None,
            submission_error: None,
            error_signature,
            occurrence_count,
            first_seen_at,
            last_seen_at,
            created_at,
        }
    }
}

