# coding: utf-8

"""
    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 OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class CrashReport(BaseModel):
    """
    A recorded application crash event with diagnostic information.
    """ # noqa: E501
    id: StrictStr = Field(description="Unique identifier for the crash report.")
    error_type: StrictStr = Field(description="Classification of the error (e.g. panic, segfault, oom).")
    error_message: StrictStr = Field(description="Human-readable error message captured at crash time.")
    stack_trace: Optional[StrictStr] = Field(default=None, description="Full stack trace captured at the point of failure.")
    component: StrictStr = Field(description="Application component or subsystem where the crash originated.")
    severity: StrictStr = Field(description="Severity level of the crash (e.g. critical, error, warning).")
    app_version: StrictStr = Field(description="Application version string at the time of the crash.")
    os_info: Optional[StrictStr] = Field(default=None, description="Operating system and platform information.")
    uptime_seconds: Optional[StrictInt] = Field(default=None, description="Application uptime in seconds before the crash occurred.")
    context: Dict[str, Any] = Field(description="Arbitrary key-value metadata providing additional crash context.")
    submitted: StrictBool = Field(description="Whether this crash report has been submitted to the telemetry service.")
    submitted_at: Optional[datetime] = Field(default=None, description="Timestamp when the crash report was submitted.")
    submission_error: Optional[StrictStr] = Field(default=None, description="Error message if the most recent submission attempt failed.")
    error_signature: StrictStr = Field(description="Deduplicated signature derived from the error type and stack trace.")
    occurrence_count: StrictInt = Field(description="Number of times this crash (by signature) has been observed.")
    first_seen_at: datetime = Field(description="Timestamp of the first occurrence of this crash signature.")
    last_seen_at: datetime = Field(description="Timestamp of the most recent occurrence of this crash signature.")
    created_at: datetime = Field(description="Timestamp when this crash report record was created.")
    __properties: ClassVar[List[str]] = ["id", "error_type", "error_message", "stack_trace", "component", "severity", "app_version", "os_info", "uptime_seconds", "context", "submitted", "submitted_at", "submission_error", "error_signature", "occurrence_count", "first_seen_at", "last_seen_at", "created_at"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of CrashReport from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if stack_trace (nullable) is None
        # and model_fields_set contains the field
        if self.stack_trace is None and "stack_trace" in self.model_fields_set:
            _dict['stack_trace'] = None

        # set to None if os_info (nullable) is None
        # and model_fields_set contains the field
        if self.os_info is None and "os_info" in self.model_fields_set:
            _dict['os_info'] = None

        # set to None if uptime_seconds (nullable) is None
        # and model_fields_set contains the field
        if self.uptime_seconds is None and "uptime_seconds" in self.model_fields_set:
            _dict['uptime_seconds'] = None

        # set to None if submitted_at (nullable) is None
        # and model_fields_set contains the field
        if self.submitted_at is None and "submitted_at" in self.model_fields_set:
            _dict['submitted_at'] = None

        # set to None if submission_error (nullable) is None
        # and model_fields_set contains the field
        if self.submission_error is None and "submission_error" in self.model_fields_set:
            _dict['submission_error'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CrashReport from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "error_type": obj.get("error_type"),
            "error_message": obj.get("error_message"),
            "stack_trace": obj.get("stack_trace"),
            "component": obj.get("component"),
            "severity": obj.get("severity"),
            "app_version": obj.get("app_version"),
            "os_info": obj.get("os_info"),
            "uptime_seconds": obj.get("uptime_seconds"),
            "context": obj.get("context"),
            "submitted": obj.get("submitted"),
            "submitted_at": obj.get("submitted_at"),
            "submission_error": obj.get("submission_error"),
            "error_signature": obj.get("error_signature"),
            "occurrence_count": obj.get("occurrence_count"),
            "first_seen_at": obj.get("first_seen_at"),
            "last_seen_at": obj.get("last_seen_at"),
            "created_at": obj.get("created_at")
        })
        return _obj


