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

class GetCveTrends200Response(BaseModel):
    """
    GetCveTrends200Response
    """ # noqa: E501
    period_days: StrictInt = Field(description="Number of days covered by the trend window.")
    total_cves: StrictInt = Field(description="Total open CVEs at the end of the period.")
    new_cves: StrictInt = Field(description="CVEs first detected during the period.")
    resolved_cves: StrictInt = Field(description="CVEs resolved during the period.")
    by_severity: Dict[str, StrictInt] = Field(description="Counts keyed by severity level (critical, high, medium, low).")
    daily: List[GetCveTrends200ResponseDailyInner] = Field(description="Per-day breakdown of CVE counts.")
    __properties: ClassVar[List[str]] = ["period_days", "total_cves", "new_cves", "resolved_cves", "by_severity", "daily"]

    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 GetCveTrends200Response 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 daily (list)
        _items = []
        if self.daily:
            for _item_daily in self.daily:
                if _item_daily:
                    _items.append(_item_daily.to_dict())
            _dict['daily'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "period_days": obj.get("period_days"),
            "total_cves": obj.get("total_cves"),
            "new_cves": obj.get("new_cves"),
            "resolved_cves": obj.get("resolved_cves"),
            "by_severity": obj.get("by_severity"),
            "daily": [GetCveTrends200ResponseDailyInner.from_dict(_item) for _item in obj["daily"]] if obj.get("daily") is not None else None
        })
        return _obj


