# 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, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from sonatype_iq_api_client.models.component_identifier import ComponentIdentifier
from typing import Optional, Set
from typing_extensions import Self

class PrioritizedComponent(BaseModel):
    """
    List of items for the current page
    """ # noqa: E501
    action: Optional[StrictStr] = None
    component_hash: Optional[StrictStr] = Field(default=None, alias="componentHash")
    component_identifier: Optional[ComponentIdentifier] = Field(default=None, alias="componentIdentifier")
    dependency_type: Optional[StrictStr] = Field(default=None, alias="dependencyType")
    display_name: Optional[StrictStr] = Field(default=None, alias="displayName")
    has_auto_waiver: Optional[StrictBool] = Field(default=None, alias="hasAutoWaiver")
    has_expired_waiver: Optional[StrictBool] = Field(default=None, alias="hasExpiredWaiver")
    has_fail_action_on_component: Optional[StrictBool] = Field(default=None, alias="hasFailActionOnComponent")
    has_same_violations_on_main: Optional[StrictBool] = Field(default=None, alias="hasSameViolationsOnMain")
    has_soon_to_expire_waiver: Optional[StrictBool] = Field(default=None, alias="hasSoonToExpireWaiver")
    highest_reachable_threat: Optional[StrictInt] = Field(default=None, alias="highestReachableThreat")
    highest_threat: Optional[StrictInt] = Field(default=None, alias="highestThreat")
    highest_threat_policy_constraint_name: Optional[StrictStr] = Field(default=None, alias="highestThreatPolicyConstraintName")
    highest_threat_policy_name: Optional[StrictStr] = Field(default=None, alias="highestThreatPolicyName")
    is_all_violations_waived: Optional[StrictBool] = Field(default=None, alias="isAllViolationsWaived")
    priority: Optional[StrictInt] = None
    remediation_type: Optional[StrictStr] = Field(default=None, alias="remediationType")
    remediation_version: Optional[StrictStr] = Field(default=None, alias="remediationVersion")
    security_reachable: Optional[StrictBool] = Field(default=None, alias="securityReachable")
    waived_violations_count: Optional[StrictInt] = Field(default=None, alias="waivedViolationsCount")
    waiver_expiration_details: Optional[StrictStr] = Field(default=None, alias="waiverExpirationDetails")
    __properties: ClassVar[List[str]] = ["action", "componentHash", "componentIdentifier", "dependencyType", "displayName", "hasAutoWaiver", "hasExpiredWaiver", "hasFailActionOnComponent", "hasSameViolationsOnMain", "hasSoonToExpireWaiver", "highestReachableThreat", "highestThreat", "highestThreatPolicyConstraintName", "highestThreatPolicyName", "isAllViolationsWaived", "priority", "remediationType", "remediationVersion", "securityReachable", "waivedViolationsCount", "waiverExpirationDetails"]

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

        if value not in set(['next-no-violations', 'next-non-failing', 'next-no-violations-with-dependencies', 'next-non-failing-with-dependencies', 'inner-source-latest-non-breaking', 'inner-source-latest', 'recommended-non-breaking', 'recommended-non-breaking-with-dependencies']):
            raise ValueError("must be one of enum values ('next-no-violations', 'next-non-failing', 'next-no-violations-with-dependencies', 'next-non-failing-with-dependencies', 'inner-source-latest-non-breaking', 'inner-source-latest', 'recommended-non-breaking', 'recommended-non-breaking-with-dependencies')")
        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 PrioritizedComponent 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()
        return _dict

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

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

        _obj = cls.model_validate({
            "action": obj.get("action"),
            "componentHash": obj.get("componentHash"),
            "componentIdentifier": ComponentIdentifier.from_dict(obj["componentIdentifier"]) if obj.get("componentIdentifier") is not None else None,
            "dependencyType": obj.get("dependencyType"),
            "displayName": obj.get("displayName"),
            "hasAutoWaiver": obj.get("hasAutoWaiver"),
            "hasExpiredWaiver": obj.get("hasExpiredWaiver"),
            "hasFailActionOnComponent": obj.get("hasFailActionOnComponent"),
            "hasSameViolationsOnMain": obj.get("hasSameViolationsOnMain"),
            "hasSoonToExpireWaiver": obj.get("hasSoonToExpireWaiver"),
            "highestReachableThreat": obj.get("highestReachableThreat"),
            "highestThreat": obj.get("highestThreat"),
            "highestThreatPolicyConstraintName": obj.get("highestThreatPolicyConstraintName"),
            "highestThreatPolicyName": obj.get("highestThreatPolicyName"),
            "isAllViolationsWaived": obj.get("isAllViolationsWaived"),
            "priority": obj.get("priority"),
            "remediationType": obj.get("remediationType"),
            "remediationVersion": obj.get("remediationVersion"),
            "securityReachable": obj.get("securityReachable"),
            "waivedViolationsCount": obj.get("waivedViolationsCount"),
            "waiverExpirationDetails": obj.get("waiverExpirationDetails")
        })
        return _obj


