# 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.184.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
from typing import Any, ClassVar, Dict, List, Optional
from sonatype_iq_api_client.models.api_component_identifier_dtov2 import ApiComponentIdentifierDTOV2
from sonatype_iq_api_client.models.api_dependency_data_dto import ApiDependencyDataDTO
from sonatype_iq_api_client.models.api_license_data_dtov2 import ApiLicenseDataDTOV2
from sonatype_iq_api_client.models.api_security_data_dto import ApiSecurityDataDTO
from sonatype_iq_api_client.models.swid import Swid
from typing import Optional, Set
from typing_extensions import Self

class ApiReportComponentDTOV2(BaseModel):
    """
    ApiReportComponentDTOV2
    """ # noqa: E501
    component_identifier: Optional[ApiComponentIdentifierDTOV2] = Field(default=None, alias="componentIdentifier")
    cpe: Optional[StrictStr] = None
    dependency_data: Optional[ApiDependencyDataDTO] = Field(default=None, alias="dependencyData")
    display_name: Optional[StrictStr] = Field(default=None, alias="displayName")
    filenames: Optional[List[StrictStr]] = None
    hash: Optional[StrictStr] = None
    identification_source: Optional[StrictStr] = Field(default=None, alias="identificationSource")
    license_data: Optional[ApiLicenseDataDTOV2] = Field(default=None, alias="licenseData")
    match_state: Optional[StrictStr] = Field(default=None, alias="matchState")
    package_url: Optional[StrictStr] = Field(default=None, alias="packageUrl")
    pathnames: Optional[List[StrictStr]] = None
    proprietary: Optional[StrictBool] = None
    security_data: Optional[ApiSecurityDataDTO] = Field(default=None, alias="securityData")
    sha256: Optional[StrictStr] = None
    swid: Optional[Swid] = None
    third_party: Optional[StrictBool] = Field(default=None, alias="thirdParty")
    __properties: ClassVar[List[str]] = ["componentIdentifier", "cpe", "dependencyData", "displayName", "filenames", "hash", "identificationSource", "licenseData", "matchState", "packageUrl", "pathnames", "proprietary", "securityData", "sha256", "swid", "thirdParty"]

    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 ApiReportComponentDTOV2 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_identifier
        if self.component_identifier:
            _dict['componentIdentifier'] = self.component_identifier.to_dict()
        # override the default output from pydantic by calling `to_dict()` of dependency_data
        if self.dependency_data:
            _dict['dependencyData'] = self.dependency_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of license_data
        if self.license_data:
            _dict['licenseData'] = self.license_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of security_data
        if self.security_data:
            _dict['securityData'] = self.security_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of swid
        if self.swid:
            _dict['swid'] = self.swid.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "componentIdentifier": ApiComponentIdentifierDTOV2.from_dict(obj["componentIdentifier"]) if obj.get("componentIdentifier") is not None else None,
            "cpe": obj.get("cpe"),
            "dependencyData": ApiDependencyDataDTO.from_dict(obj["dependencyData"]) if obj.get("dependencyData") is not None else None,
            "displayName": obj.get("displayName"),
            "filenames": obj.get("filenames"),
            "hash": obj.get("hash"),
            "identificationSource": obj.get("identificationSource"),
            "licenseData": ApiLicenseDataDTOV2.from_dict(obj["licenseData"]) if obj.get("licenseData") is not None else None,
            "matchState": obj.get("matchState"),
            "packageUrl": obj.get("packageUrl"),
            "pathnames": obj.get("pathnames"),
            "proprietary": obj.get("proprietary"),
            "securityData": ApiSecurityDataDTO.from_dict(obj["securityData"]) if obj.get("securityData") is not None else None,
            "sha256": obj.get("sha256"),
            "swid": Swid.from_dict(obj["swid"]) if obj.get("swid") is not None else None,
            "thirdParty": obj.get("thirdParty")
        })
        return _obj


