# 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.197.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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from sonatype_iq_api_client.models.api_component_dtov2 import ApiComponentDTOV2
from sonatype_iq_api_client.models.api_component_policy_violation_list_dtov2 import ApiComponentPolicyViolationListDTOV2
from sonatype_iq_api_client.models.api_component_project_data_dto import ApiComponentProjectDataDTO
from sonatype_iq_api_client.models.api_license_data_dto import ApiLicenseDataDTO
from sonatype_iq_api_client.models.api_security_data_dto import ApiSecurityDataDTO
from typing import Optional, Set
from typing_extensions import Self

class ApiComponentDetailsDTOV2(BaseModel):
    """
    ApiComponentDetailsDTOV2
    """ # noqa: E501
    catalog_date: Optional[StrictStr] = Field(default=None, alias="catalogDate")
    component: Optional[ApiComponentDTOV2] = None
    hygiene_rating: Optional[StrictStr] = Field(default=None, alias="hygieneRating")
    integrity_rating: Optional[StrictStr] = Field(default=None, alias="integrityRating")
    license_data: Optional[ApiLicenseDataDTO] = Field(default=None, alias="licenseData")
    match_state: Optional[StrictStr] = Field(default=None, alias="matchState")
    policy_data: Optional[ApiComponentPolicyViolationListDTOV2] = Field(default=None, alias="policyData")
    project_data: Optional[ApiComponentProjectDataDTO] = Field(default=None, alias="projectData")
    relative_popularity: Optional[StrictInt] = Field(default=None, alias="relativePopularity")
    security_data: Optional[ApiSecurityDataDTO] = Field(default=None, alias="securityData")
    __properties: ClassVar[List[str]] = ["catalogDate", "component", "hygieneRating", "integrityRating", "licenseData", "matchState", "policyData", "projectData", "relativePopularity", "securityData"]

    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 ApiComponentDetailsDTOV2 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 license_data
        if self.license_data:
            _dict['licenseData'] = self.license_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of policy_data
        if self.policy_data:
            _dict['policyData'] = self.policy_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of project_data
        if self.project_data:
            _dict['projectData'] = self.project_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()
        # set to None if hygiene_rating (nullable) is None
        # and model_fields_set contains the field
        if self.hygiene_rating is None and "hygiene_rating" in self.model_fields_set:
            _dict['hygieneRating'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "catalogDate": obj.get("catalogDate"),
            "component": ApiComponentDTOV2.from_dict(obj["component"]) if obj.get("component") is not None else None,
            "hygieneRating": obj.get("hygieneRating"),
            "integrityRating": obj.get("integrityRating"),
            "licenseData": ApiLicenseDataDTO.from_dict(obj["licenseData"]) if obj.get("licenseData") is not None else None,
            "matchState": obj.get("matchState"),
            "policyData": ApiComponentPolicyViolationListDTOV2.from_dict(obj["policyData"]) if obj.get("policyData") is not None else None,
            "projectData": ApiComponentProjectDataDTO.from_dict(obj["projectData"]) if obj.get("projectData") is not None else None,
            "relativePopularity": obj.get("relativePopularity"),
            "securityData": ApiSecurityDataDTO.from_dict(obj["securityData"]) if obj.get("securityData") is not None else None
        })
        return _obj


