# coding: utf-8

"""
    Sonatype Lifecycle Public REST API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.196.0-01
    Contact: community@sonatype.com
    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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from sonatype_iq_api_client.models.epss_data import EpssData
from sonatype_iq_api_client.models.kev_data import KevData
from sonatype_iq_api_client.models.reference_link_dto import ReferenceLinkDTO
from sonatype_iq_api_client.models.root_cause_dto import RootCauseDTO
from sonatype_iq_api_client.models.security_vulnerability_custom_data_dto import SecurityVulnerabilityCustomDataDTO
from sonatype_iq_api_client.models.security_vulnerability_severity_dto import SecurityVulnerabilitySeverityDTO
from sonatype_iq_api_client.models.security_vulnerability_weakness_dto import SecurityVulnerabilityWeaknessDTO
from sonatype_iq_api_client.models.vulnerability_source_dto import VulnerabilitySourceDTO
from typing import Optional, Set
from typing_extensions import Self

class SecurityVulnerabilityDataDTO(BaseModel):
    """
    SecurityVulnerabilityDataDTO
    """ # noqa: E501
    advisories: Optional[List[ReferenceLinkDTO]] = None
    categories: Optional[List[StrictStr]] = None
    component_detection_markdown: Optional[StrictStr] = Field(default=None, alias="componentDetectionMarkdown")
    component_explanation_markdown: Optional[StrictStr] = Field(default=None, alias="componentExplanationMarkdown")
    component_recommendation_markdown: Optional[StrictStr] = Field(default=None, alias="componentRecommendationMarkdown")
    custom_data: Optional[SecurityVulnerabilityCustomDataDTO] = Field(default=None, alias="customData")
    description: Optional[StrictStr] = None
    detection_markdown: Optional[StrictStr] = Field(default=None, alias="detectionMarkdown")
    detection_type: Optional[StrictStr] = Field(default=None, alias="detectionType")
    epss_data: Optional[EpssData] = Field(default=None, alias="epssData")
    explanation_markdown: Optional[StrictStr] = Field(default=None, alias="explanationMarkdown")
    identification_source: Optional[StrictStr] = Field(default=None, alias="identificationSource")
    identifier: Optional[StrictStr] = None
    is_advanced_vulnerability_detection: Optional[StrictBool] = Field(default=None, alias="isAdvancedVulnerabilityDetection")
    kev_data: Optional[KevData] = Field(default=None, alias="kevData")
    main_severity: Optional[SecurityVulnerabilitySeverityDTO] = Field(default=None, alias="mainSeverity")
    recommendation_markdown: Optional[StrictStr] = Field(default=None, alias="recommendationMarkdown")
    research_type: Optional[StrictStr] = Field(default=None, alias="researchType")
    root_causes: Optional[List[RootCauseDTO]] = Field(default=None, alias="rootCauses")
    severity_scores: Optional[List[SecurityVulnerabilitySeverityDTO]] = Field(default=None, alias="severityScores")
    source: Optional[VulnerabilitySourceDTO] = None
    vuln_ids: Optional[List[StrictStr]] = Field(default=None, alias="vulnIds")
    vulnerability_link: Optional[StrictStr] = Field(default=None, alias="vulnerabilityLink")
    vulnerable_version_ranges: Optional[List[StrictStr]] = Field(default=None, alias="vulnerableVersionRanges")
    weakness: Optional[SecurityVulnerabilityWeaknessDTO] = None
    __properties: ClassVar[List[str]] = ["advisories", "categories", "componentDetectionMarkdown", "componentExplanationMarkdown", "componentRecommendationMarkdown", "customData", "description", "detectionMarkdown", "detectionType", "epssData", "explanationMarkdown", "identificationSource", "identifier", "isAdvancedVulnerabilityDetection", "kevData", "mainSeverity", "recommendationMarkdown", "researchType", "rootCauses", "severityScores", "source", "vulnIds", "vulnerabilityLink", "vulnerableVersionRanges", "weakness"]

    @field_validator('research_type')
    def research_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['FAST_TRACK', 'DEEP_DIVE', 'PUBLIC_RESEARCH', 'VENDOR_RESEARCH']):
            raise ValueError("must be one of enum values ('FAST_TRACK', 'DEEP_DIVE', 'PUBLIC_RESEARCH', 'VENDOR_RESEARCH')")
        return value

    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 SecurityVulnerabilityDataDTO 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 advisories (list)
        _items = []
        if self.advisories:
            for _item_advisories in self.advisories:
                if _item_advisories:
                    _items.append(_item_advisories.to_dict())
            _dict['advisories'] = _items
        # override the default output from pydantic by calling `to_dict()` of custom_data
        if self.custom_data:
            _dict['customData'] = self.custom_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of epss_data
        if self.epss_data:
            _dict['epssData'] = self.epss_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of kev_data
        if self.kev_data:
            _dict['kevData'] = self.kev_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of main_severity
        if self.main_severity:
            _dict['mainSeverity'] = self.main_severity.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in root_causes (list)
        _items = []
        if self.root_causes:
            for _item_root_causes in self.root_causes:
                if _item_root_causes:
                    _items.append(_item_root_causes.to_dict())
            _dict['rootCauses'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in severity_scores (list)
        _items = []
        if self.severity_scores:
            for _item_severity_scores in self.severity_scores:
                if _item_severity_scores:
                    _items.append(_item_severity_scores.to_dict())
            _dict['severityScores'] = _items
        # override the default output from pydantic by calling `to_dict()` of source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of weakness
        if self.weakness:
            _dict['weakness'] = self.weakness.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "advisories": [ReferenceLinkDTO.from_dict(_item) for _item in obj["advisories"]] if obj.get("advisories") is not None else None,
            "categories": obj.get("categories"),
            "componentDetectionMarkdown": obj.get("componentDetectionMarkdown"),
            "componentExplanationMarkdown": obj.get("componentExplanationMarkdown"),
            "componentRecommendationMarkdown": obj.get("componentRecommendationMarkdown"),
            "customData": SecurityVulnerabilityCustomDataDTO.from_dict(obj["customData"]) if obj.get("customData") is not None else None,
            "description": obj.get("description"),
            "detectionMarkdown": obj.get("detectionMarkdown"),
            "detectionType": obj.get("detectionType"),
            "epssData": EpssData.from_dict(obj["epssData"]) if obj.get("epssData") is not None else None,
            "explanationMarkdown": obj.get("explanationMarkdown"),
            "identificationSource": obj.get("identificationSource"),
            "identifier": obj.get("identifier"),
            "isAdvancedVulnerabilityDetection": obj.get("isAdvancedVulnerabilityDetection"),
            "kevData": KevData.from_dict(obj["kevData"]) if obj.get("kevData") is not None else None,
            "mainSeverity": SecurityVulnerabilitySeverityDTO.from_dict(obj["mainSeverity"]) if obj.get("mainSeverity") is not None else None,
            "recommendationMarkdown": obj.get("recommendationMarkdown"),
            "researchType": obj.get("researchType"),
            "rootCauses": [RootCauseDTO.from_dict(_item) for _item in obj["rootCauses"]] if obj.get("rootCauses") is not None else None,
            "severityScores": [SecurityVulnerabilitySeverityDTO.from_dict(_item) for _item in obj["severityScores"]] if obj.get("severityScores") is not None else None,
            "source": VulnerabilitySourceDTO.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "vulnIds": obj.get("vulnIds"),
            "vulnerabilityLink": obj.get("vulnerabilityLink"),
            "vulnerableVersionRanges": obj.get("vulnerableVersionRanges"),
            "weakness": SecurityVulnerabilityWeaknessDTO.from_dict(obj["weakness"]) if obj.get("weakness") is not None else None
        })
        return _obj


