from collections.abc import Mapping
from typing import (
    TYPE_CHECKING,
    Any,
    TypeVar,
    Union,
)

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.cwe import Cwe
    from ..models.vulnerability_alias import VulnerabilityAlias


T = TypeVar("T", bound="FindingVulnerability")


@_attrs_define
class FindingVulnerability:
    """
    Attributes:
        uuid (Union[Unset, str]):
        source (Union[Unset, str]):
        vuln_id (Union[Unset, str]):
        description (Union[Unset, str]):
        cvss_v2_base_score (Union[Unset, float]):
        cvss_v3_base_score (Union[Unset, float]):
        severity (Union[Unset, str]):
        severity_rank (Union[Unset, int]):
        epss_score (Union[Unset, float]):
        epss_percentile (Union[Unset, float]):
        cwe_id (Union[Unset, int]):
        cwe_name (Union[Unset, str]):
        cwes (Union[Unset, list['Cwe']]):
        recommendation (Union[Unset, str]):
        published (Union[Unset, int]):
        aliases (Union[Unset, list['VulnerabilityAlias']]):
    """

    uuid: Union[Unset, str] = UNSET
    source: Union[Unset, str] = UNSET
    vuln_id: Union[Unset, str] = UNSET
    description: Union[Unset, str] = UNSET
    cvss_v2_base_score: Union[Unset, float] = UNSET
    cvss_v3_base_score: Union[Unset, float] = UNSET
    severity: Union[Unset, str] = UNSET
    severity_rank: Union[Unset, int] = UNSET
    epss_score: Union[Unset, float] = UNSET
    epss_percentile: Union[Unset, float] = UNSET
    cwe_id: Union[Unset, int] = UNSET
    cwe_name: Union[Unset, str] = UNSET
    cwes: Union[Unset, list["Cwe"]] = UNSET
    recommendation: Union[Unset, str] = UNSET
    published: Union[Unset, int] = UNSET
    aliases: Union[Unset, list["VulnerabilityAlias"]] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        uuid = self.uuid

        source = self.source

        vuln_id = self.vuln_id

        description = self.description

        cvss_v2_base_score = self.cvss_v2_base_score

        cvss_v3_base_score = self.cvss_v3_base_score

        severity = self.severity

        severity_rank = self.severity_rank

        epss_score = self.epss_score

        epss_percentile = self.epss_percentile

        cwe_id = self.cwe_id

        cwe_name = self.cwe_name

        cwes: Union[Unset, list[dict[str, Any]]] = UNSET
        if not isinstance(self.cwes, Unset):
            cwes = []
            for cwes_item_data in self.cwes:
                cwes_item = cwes_item_data.to_dict()
                cwes.append(cwes_item)

        recommendation = self.recommendation

        published = self.published

        aliases: Union[Unset, list[dict[str, Any]]] = UNSET
        if not isinstance(self.aliases, Unset):
            aliases = []
            for aliases_item_data in self.aliases:
                aliases_item = aliases_item_data.to_dict()
                aliases.append(aliases_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if uuid is not UNSET:
            field_dict["uuid"] = uuid
        if source is not UNSET:
            field_dict["source"] = source
        if vuln_id is not UNSET:
            field_dict["vulnId"] = vuln_id
        if description is not UNSET:
            field_dict["description"] = description
        if cvss_v2_base_score is not UNSET:
            field_dict["cvssV2BaseScore"] = cvss_v2_base_score
        if cvss_v3_base_score is not UNSET:
            field_dict["cvssV3BaseScore"] = cvss_v3_base_score
        if severity is not UNSET:
            field_dict["severity"] = severity
        if severity_rank is not UNSET:
            field_dict["severityRank"] = severity_rank
        if epss_score is not UNSET:
            field_dict["epssScore"] = epss_score
        if epss_percentile is not UNSET:
            field_dict["epssPercentile"] = epss_percentile
        if cwe_id is not UNSET:
            field_dict["cweId"] = cwe_id
        if cwe_name is not UNSET:
            field_dict["cweName"] = cwe_name
        if cwes is not UNSET:
            field_dict["cwes"] = cwes
        if recommendation is not UNSET:
            field_dict["recommendation"] = recommendation
        if published is not UNSET:
            field_dict["published"] = published
        if aliases is not UNSET:
            field_dict["aliases"] = aliases

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.cwe import Cwe
        from ..models.vulnerability_alias import VulnerabilityAlias

        d = dict(src_dict)
        uuid = d.pop("uuid", UNSET)

        source = d.pop("source", UNSET)

        vuln_id = d.pop("vulnId", UNSET)

        description = d.pop("description", UNSET)

        cvss_v2_base_score = d.pop("cvssV2BaseScore", UNSET)

        cvss_v3_base_score = d.pop("cvssV3BaseScore", UNSET)

        severity = d.pop("severity", UNSET)

        severity_rank = d.pop("severityRank", UNSET)

        epss_score = d.pop("epssScore", UNSET)

        epss_percentile = d.pop("epssPercentile", UNSET)

        cwe_id = d.pop("cweId", UNSET)

        cwe_name = d.pop("cweName", UNSET)

        cwes = []
        _cwes = d.pop("cwes", UNSET)
        for cwes_item_data in _cwes or []:
            cwes_item = Cwe.from_dict(cwes_item_data)

            cwes.append(cwes_item)

        recommendation = d.pop("recommendation", UNSET)

        published = d.pop("published", UNSET)

        aliases = []
        _aliases = d.pop("aliases", UNSET)
        for aliases_item_data in _aliases or []:
            aliases_item = VulnerabilityAlias.from_dict(aliases_item_data)

            aliases.append(aliases_item)

        finding_vulnerability = cls(
            uuid=uuid,
            source=source,
            vuln_id=vuln_id,
            description=description,
            cvss_v2_base_score=cvss_v2_base_score,
            cvss_v3_base_score=cvss_v3_base_score,
            severity=severity,
            severity_rank=severity_rank,
            epss_score=epss_score,
            epss_percentile=epss_percentile,
            cwe_id=cwe_id,
            cwe_name=cwe_name,
            cwes=cwes,
            recommendation=recommendation,
            published=published,
            aliases=aliases,
        )

        finding_vulnerability.additional_properties = d
        return finding_vulnerability

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
