# 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.196.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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class VulnerabilityAnalysis(BaseModel):
    """
    Vulnerability analysis details.
    """ # noqa: E501
    created_on: Optional[datetime] = Field(default=None, alias="createdOn")
    detail: StrictStr = Field(description="Detailed description of the impact including methods used during assessment")
    justification: StrictStr = Field(description="The rationale of why the impact analysis state was asserted")
    last_updated_by: Optional[StrictStr] = Field(default=None, alias="lastUpdatedBy")
    last_updated_on: Optional[datetime] = Field(default=None, alias="lastUpdatedOn")
    response: StrictStr = Field(description="Vulnerability analysis response by an author, supplier or manufacturer for the affected component.")
    state: StrictStr = Field(description="Vulnerability analysis state.")
    __properties: ClassVar[List[str]] = ["createdOn", "detail", "justification", "lastUpdatedBy", "lastUpdatedOn", "response", "state"]

    @field_validator('justification')
    def justification_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['code_not_present', 'code_not_reachable', 'requires_configuration', 'requires_dependency', 'requires_environment', 'protected_by_compiler', 'protected_at_runtime', 'protected_at_perimeter', 'protected_by_mitigating_control']):
            raise ValueError("must be one of enum values ('code_not_present', 'code_not_reachable', 'requires_configuration', 'requires_dependency', 'requires_environment', 'protected_by_compiler', 'protected_at_runtime', 'protected_at_perimeter', 'protected_by_mitigating_control')")
        return value

    @field_validator('response')
    def response_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['can_not_fix', 'will_not_fix', 'update', 'rollback', 'workaround_available']):
            raise ValueError("must be one of enum values ('can_not_fix', 'will_not_fix', 'update', 'rollback', 'workaround_available')")
        return value

    @field_validator('state')
    def state_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['resolved', 'resolved_with_pedigree', 'exploitable', 'in_triage', 'false_positive', 'not_affected']):
            raise ValueError("must be one of enum values ('resolved', 'resolved_with_pedigree', 'exploitable', 'in_triage', 'false_positive', 'not_affected')")
        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 VulnerabilityAnalysis 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "created_on",
            "last_updated_by",
            "last_updated_on",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "createdOn": obj.get("createdOn"),
            "detail": obj.get("detail"),
            "justification": obj.get("justification"),
            "lastUpdatedBy": obj.get("lastUpdatedBy"),
            "lastUpdatedOn": obj.get("lastUpdatedOn"),
            "response": obj.get("response"),
            "state": obj.get("state")
        })
        return _obj


