# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

class CveHistoryEntry(BaseModel):
    """
    CVE history entry for tracking vulnerability timeline.
    """ # noqa: E501
    acknowledged_at: Optional[datetime] = None
    acknowledged_by: Optional[StrictStr] = None
    acknowledged_reason: Optional[StrictStr] = None
    affected_component: Optional[StrictStr] = None
    affected_version: Optional[StrictStr] = None
    artifact_id: StrictStr
    component_id: Optional[StrictStr] = None
    created_at: datetime
    cve_id: StrictStr
    cve_published_at: Optional[datetime] = None
    cvss_score: Optional[Union[StrictFloat, StrictInt]] = None
    first_detected_at: datetime
    fixed_version: Optional[StrictStr] = None
    id: StrictStr
    last_detected_at: datetime
    sbom_id: Optional[StrictStr] = None
    scan_result_id: Optional[StrictStr] = None
    severity: Optional[StrictStr] = None
    status: StrictStr
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["acknowledged_at", "acknowledged_by", "acknowledged_reason", "affected_component", "affected_version", "artifact_id", "component_id", "created_at", "cve_id", "cve_published_at", "cvss_score", "first_detected_at", "fixed_version", "id", "last_detected_at", "sbom_id", "scan_result_id", "severity", "status", "updated_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 CveHistoryEntry 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 acknowledged_at (nullable) is None
        # and model_fields_set contains the field
        if self.acknowledged_at is None and "acknowledged_at" in self.model_fields_set:
            _dict['acknowledged_at'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "acknowledged_at": obj.get("acknowledged_at"),
            "acknowledged_by": obj.get("acknowledged_by"),
            "acknowledged_reason": obj.get("acknowledged_reason"),
            "affected_component": obj.get("affected_component"),
            "affected_version": obj.get("affected_version"),
            "artifact_id": obj.get("artifact_id"),
            "component_id": obj.get("component_id"),
            "created_at": obj.get("created_at"),
            "cve_id": obj.get("cve_id"),
            "cve_published_at": obj.get("cve_published_at"),
            "cvss_score": obj.get("cvss_score"),
            "first_detected_at": obj.get("first_detected_at"),
            "fixed_version": obj.get("fixed_version"),
            "id": obj.get("id"),
            "last_detected_at": obj.get("last_detected_at"),
            "sbom_id": obj.get("sbom_id"),
            "scan_result_id": obj.get("scan_result_id"),
            "severity": obj.get("severity"),
            "status": obj.get("status"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


