# 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 pydantic import BaseModel, ConfigDict, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from artifact_keeper_client.models.cve_timeline_entry import CveTimelineEntry
from typing import Optional, Set
from typing_extensions import Self

class CveTrends(BaseModel):
    """
    CVE trends summary.
    """ # noqa: E501
    acknowledged_cves: StrictInt
    avg_days_to_fix: Optional[Union[StrictFloat, StrictInt]] = None
    critical_count: StrictInt
    fixed_cves: StrictInt
    high_count: StrictInt
    low_count: StrictInt
    medium_count: StrictInt
    open_cves: StrictInt
    timeline: List[CveTimelineEntry]
    total_cves: StrictInt
    __properties: ClassVar[List[str]] = ["acknowledged_cves", "avg_days_to_fix", "critical_count", "fixed_cves", "high_count", "low_count", "medium_count", "open_cves", "timeline", "total_cves"]

    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 CveTrends 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,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in timeline (list)
        _items = []
        if self.timeline:
            for _item_timeline in self.timeline:
                if _item_timeline:
                    _items.append(_item_timeline.to_dict())
            _dict['timeline'] = _items
        # set to None if avg_days_to_fix (nullable) is None
        # and model_fields_set contains the field
        if self.avg_days_to_fix is None and "avg_days_to_fix" in self.model_fields_set:
            _dict['avg_days_to_fix'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "acknowledged_cves": obj.get("acknowledged_cves"),
            "avg_days_to_fix": obj.get("avg_days_to_fix"),
            "critical_count": obj.get("critical_count"),
            "fixed_cves": obj.get("fixed_cves"),
            "high_count": obj.get("high_count"),
            "low_count": obj.get("low_count"),
            "medium_count": obj.get("medium_count"),
            "open_cves": obj.get("open_cves"),
            "timeline": [CveTimelineEntry.from_dict(_item) for _item in obj["timeline"]] if obj.get("timeline") is not None else None,
            "total_cves": obj.get("total_cves")
        })
        return _obj


