# 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
from typing import Any, ClassVar, Dict, List, Optional
from artifact_keeper_client.models.dt_analysis import DtAnalysis
from artifact_keeper_client.models.dt_attribution import DtAttribution
from artifact_keeper_client.models.dt_component import DtComponent
from artifact_keeper_client.models.dt_vulnerability import DtVulnerability
from typing import Optional, Set
from typing_extensions import Self

class DtFinding(BaseModel):
    """
    DtFinding
    """ # noqa: E501
    component: DtComponent
    vulnerability: DtVulnerability
    analysis: Optional[DtAnalysis] = None
    attribution: Optional[DtAttribution] = None
    __properties: ClassVar[List[str]] = ["component", "vulnerability", "analysis", "attribution"]

    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 DtFinding 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 component
        if self.component:
            _dict['component'] = self.component.to_dict()
        # override the default output from pydantic by calling `to_dict()` of vulnerability
        if self.vulnerability:
            _dict['vulnerability'] = self.vulnerability.to_dict()
        # override the default output from pydantic by calling `to_dict()` of analysis
        if self.analysis:
            _dict['analysis'] = self.analysis.to_dict()
        # override the default output from pydantic by calling `to_dict()` of attribution
        if self.attribution:
            _dict['attribution'] = self.attribution.to_dict()
        # set to None if analysis (nullable) is None
        # and model_fields_set contains the field
        if self.analysis is None and "analysis" in self.model_fields_set:
            _dict['analysis'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "component": DtComponent.from_dict(obj["component"]) if obj.get("component") is not None else None,
            "vulnerability": DtVulnerability.from_dict(obj["vulnerability"]) if obj.get("vulnerability") is not None else None,
            "analysis": DtAnalysis.from_dict(obj["analysis"]) if obj.get("analysis") is not None else None,
            "attribution": DtAttribution.from_dict(obj["attribution"]) if obj.get("attribution") is not None else None
        })
        return _obj


