# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
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_constraint_violation_dto import ApiConstraintViolationDTO
from sonatype_iq_api_client.models.component_display_name import ComponentDisplayName
from sonatype_iq_api_client.models.policy_owner import PolicyOwner
from sonatype_iq_api_client.models.stage_data import StageData
from typing import Optional, Set
from typing_extensions import Self

class ApiCrossStageViolationDTOV2(BaseModel):
    """
    ApiCrossStageViolationDTOV2
    """ # noqa: E501
    application_name: Optional[StrictStr] = Field(default=None, alias="applicationName")
    application_public_id: Optional[StrictStr] = Field(default=None, alias="applicationPublicId")
    component_identifier: Optional[ApiComponentIdentifierDTOV2] = Field(default=None, alias="componentIdentifier")
    constraint_violations: Optional[List[ApiConstraintViolationDTO]] = Field(default=None, alias="constraintViolations")
    display_name: Optional[ComponentDisplayName] = Field(default=None, alias="displayName")
    filename: Optional[StrictStr] = None
    fix_time: Optional[datetime] = Field(default=None, alias="fixTime")
    hash: Optional[StrictStr] = None
    open_time: Optional[datetime] = Field(default=None, alias="openTime")
    organization_name: Optional[StrictStr] = Field(default=None, alias="organizationName")
    policy_id: Optional[StrictStr] = Field(default=None, alias="policyId")
    policy_name: Optional[StrictStr] = Field(default=None, alias="policyName")
    policy_owner: Optional[PolicyOwner] = Field(default=None, alias="policyOwner")
    policy_threat_category: Optional[StrictStr] = Field(default=None, alias="policyThreatCategory")
    policy_violation_id: Optional[StrictStr] = Field(default=None, alias="policyViolationId")
    reachability_status: Optional[StrictStr] = Field(default=None, alias="reachabilityStatus")
    stage_data: Optional[Dict[str, StageData]] = Field(default=None, alias="stageData")
    threat_level: Optional[StrictInt] = Field(default=None, alias="threatLevel")
    __properties: ClassVar[List[str]] = ["applicationName", "applicationPublicId", "componentIdentifier", "constraintViolations", "displayName", "filename", "fixTime", "hash", "openTime", "organizationName", "policyId", "policyName", "policyOwner", "policyThreatCategory", "policyViolationId", "reachabilityStatus", "stageData", "threatLevel"]

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

        if value not in set(['REACHABLE', 'NON_REACHABLE']):
            raise ValueError("must be one of enum values ('REACHABLE', 'NON_REACHABLE')")
        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 ApiCrossStageViolationDTOV2 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 each item in constraint_violations (list)
        _items = []
        if self.constraint_violations:
            for _item_constraint_violations in self.constraint_violations:
                if _item_constraint_violations:
                    _items.append(_item_constraint_violations.to_dict())
            _dict['constraintViolations'] = _items
        # override the default output from pydantic by calling `to_dict()` of display_name
        if self.display_name:
            _dict['displayName'] = self.display_name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of policy_owner
        if self.policy_owner:
            _dict['policyOwner'] = self.policy_owner.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in stage_data (dict)
        _field_dict = {}
        if self.stage_data:
            for _key_stage_data in self.stage_data:
                if self.stage_data[_key_stage_data]:
                    _field_dict[_key_stage_data] = self.stage_data[_key_stage_data].to_dict()
            _dict['stageData'] = _field_dict
        return _dict

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

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

        _obj = cls.model_validate({
            "applicationName": obj.get("applicationName"),
            "applicationPublicId": obj.get("applicationPublicId"),
            "componentIdentifier": ApiComponentIdentifierDTOV2.from_dict(obj["componentIdentifier"]) if obj.get("componentIdentifier") is not None else None,
            "constraintViolations": [ApiConstraintViolationDTO.from_dict(_item) for _item in obj["constraintViolations"]] if obj.get("constraintViolations") is not None else None,
            "displayName": ComponentDisplayName.from_dict(obj["displayName"]) if obj.get("displayName") is not None else None,
            "filename": obj.get("filename"),
            "fixTime": obj.get("fixTime"),
            "hash": obj.get("hash"),
            "openTime": obj.get("openTime"),
            "organizationName": obj.get("organizationName"),
            "policyId": obj.get("policyId"),
            "policyName": obj.get("policyName"),
            "policyOwner": PolicyOwner.from_dict(obj["policyOwner"]) if obj.get("policyOwner") is not None else None,
            "policyThreatCategory": obj.get("policyThreatCategory"),
            "policyViolationId": obj.get("policyViolationId"),
            "reachabilityStatus": obj.get("reachabilityStatus"),
            "stageData": dict(
                (_k, StageData.from_dict(_v))
                for _k, _v in obj["stageData"].items()
            )
            if obj.get("stageData") is not None
            else None,
            "threatLevel": obj.get("threatLevel")
        })
        return _obj


