# coding: utf-8

"""
    Artifact Keeper API

    Enterprise artifact registry supporting 45+ package formats.

    The version of the OpenAPI document: 1.0.0-rc.3
    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, 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 stored crash report.
    """ # noqa: E501
    app_version: StrictStr
    component: StrictStr
    context: Dict[str, Any]
    created_at: datetime
    error_message: StrictStr
    error_signature: StrictStr
    error_type: StrictStr
    first_seen_at: datetime
    id: StrictStr
    last_seen_at: datetime
    occurrence_count: StrictInt
    os_info: Optional[StrictStr] = None
    severity: StrictStr
    stack_trace: Optional[StrictStr] = None
    submission_error: Optional[StrictStr] = None
    submitted: StrictBool
    submitted_at: Optional[datetime] = None
    uptime_seconds: Optional[StrictInt] = None
    __properties: ClassVar[List[str]] = ["app_version", "component", "context", "created_at", "error_message", "error_signature", "error_type", "first_seen_at", "id", "last_seen_at", "occurrence_count", "os_info", "severity", "stack_trace", "submission_error", "submitted", "submitted_at", "uptime_seconds"]

    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 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 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 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

        # 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 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

        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({
            "app_version": obj.get("app_version"),
            "component": obj.get("component"),
            "context": obj.get("context"),
            "created_at": obj.get("created_at"),
            "error_message": obj.get("error_message"),
            "error_signature": obj.get("error_signature"),
            "error_type": obj.get("error_type"),
            "first_seen_at": obj.get("first_seen_at"),
            "id": obj.get("id"),
            "last_seen_at": obj.get("last_seen_at"),
            "occurrence_count": obj.get("occurrence_count"),
            "os_info": obj.get("os_info"),
            "severity": obj.get("severity"),
            "stack_trace": obj.get("stack_trace"),
            "submission_error": obj.get("submission_error"),
            "submitted": obj.get("submitted"),
            "submitted_at": obj.get("submitted_at"),
            "uptime_seconds": obj.get("uptime_seconds")
        })
        return _obj


