# 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, StrictBool, 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.component_display_name import ComponentDisplayName
from sonatype_iq_api_client.models.constraint_fact import ConstraintFact
from typing import Optional, Set
from typing_extensions import Self

class ApiPolicyWaiverRequestDTO(BaseModel):
    """
    ApiPolicyWaiverRequestDTO
    """ # noqa: E501
    associated_package_url: Optional[StrictStr] = Field(default=None, alias="associatedPackageUrl")
    comment: Optional[StrictStr] = None
    component_identifier: Optional[ApiComponentIdentifierDTOV2] = Field(default=None, alias="componentIdentifier")
    component_name: Optional[StrictStr] = Field(default=None, alias="componentName")
    component_upgrade_available: Optional[StrictBool] = Field(default=None, alias="componentUpgradeAvailable")
    constraint_facts: Optional[List[ConstraintFact]] = Field(default=None, alias="constraintFacts")
    constraint_facts_json: Optional[StrictStr] = Field(default=None, alias="constraintFactsJson")
    display_name: Optional[ComponentDisplayName] = Field(default=None, alias="displayName")
    expire_when_remediation_available: Optional[StrictBool] = Field(default=None, alias="expireWhenRemediationAvailable")
    expiry_time: Optional[datetime] = Field(default=None, alias="expiryTime")
    hash: Optional[StrictStr] = None
    is_obsolete: Optional[StrictBool] = Field(default=None, alias="isObsolete")
    matcher_strategy: Optional[StrictStr] = Field(default=None, alias="matcherStrategy")
    note_to_reviewer: Optional[StrictStr] = Field(default=None, alias="noteToReviewer")
    policy_id: Optional[StrictStr] = Field(default=None, alias="policyId")
    policy_name: Optional[StrictStr] = Field(default=None, alias="policyName")
    policy_violation_id: Optional[StrictStr] = Field(default=None, alias="policyViolationId")
    policy_waiver_reason_id: Optional[StrictStr] = Field(default=None, alias="policyWaiverReasonId")
    policy_waiver_request_id: Optional[StrictStr] = Field(default=None, alias="policyWaiverRequestId")
    reason_text: Optional[StrictStr] = Field(default=None, alias="reasonText")
    rejection_reason: Optional[StrictStr] = Field(default=None, alias="rejectionReason")
    request_time: Optional[datetime] = Field(default=None, alias="requestTime")
    requester_id: Optional[StrictStr] = Field(default=None, alias="requesterId")
    requester_name: Optional[StrictStr] = Field(default=None, alias="requesterName")
    reviewer_id: Optional[StrictStr] = Field(default=None, alias="reviewerId")
    reviewer_name: Optional[StrictStr] = Field(default=None, alias="reviewerName")
    scope_owner_id: Optional[StrictStr] = Field(default=None, alias="scopeOwnerId")
    scope_owner_name: Optional[StrictStr] = Field(default=None, alias="scopeOwnerName")
    scope_owner_type: Optional[StrictStr] = Field(default=None, alias="scopeOwnerType")
    status: Optional[StrictStr] = None
    threat_level: Optional[StrictInt] = Field(default=None, alias="threatLevel")
    vulnerability_id: Optional[StrictStr] = Field(default=None, alias="vulnerabilityId")
    __properties: ClassVar[List[str]] = ["associatedPackageUrl", "comment", "componentIdentifier", "componentName", "componentUpgradeAvailable", "constraintFacts", "constraintFactsJson", "displayName", "expireWhenRemediationAvailable", "expiryTime", "hash", "isObsolete", "matcherStrategy", "noteToReviewer", "policyId", "policyName", "policyViolationId", "policyWaiverReasonId", "policyWaiverRequestId", "reasonText", "rejectionReason", "requestTime", "requesterId", "requesterName", "reviewerId", "reviewerName", "scopeOwnerId", "scopeOwnerName", "scopeOwnerType", "status", "threatLevel", "vulnerabilityId"]

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

        if value not in set(['DEFAULT', 'EXACT_COMPONENT', 'ALL_COMPONENTS', 'ALL_VERSIONS']):
            raise ValueError("must be one of enum values ('DEFAULT', 'EXACT_COMPONENT', 'ALL_COMPONENTS', 'ALL_VERSIONS')")
        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 ApiPolicyWaiverRequestDTO 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_facts (list)
        _items = []
        if self.constraint_facts:
            for _item_constraint_facts in self.constraint_facts:
                if _item_constraint_facts:
                    _items.append(_item_constraint_facts.to_dict())
            _dict['constraintFacts'] = _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()
        return _dict

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

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

        _obj = cls.model_validate({
            "associatedPackageUrl": obj.get("associatedPackageUrl"),
            "comment": obj.get("comment"),
            "componentIdentifier": ApiComponentIdentifierDTOV2.from_dict(obj["componentIdentifier"]) if obj.get("componentIdentifier") is not None else None,
            "componentName": obj.get("componentName"),
            "componentUpgradeAvailable": obj.get("componentUpgradeAvailable"),
            "constraintFacts": [ConstraintFact.from_dict(_item) for _item in obj["constraintFacts"]] if obj.get("constraintFacts") is not None else None,
            "constraintFactsJson": obj.get("constraintFactsJson"),
            "displayName": ComponentDisplayName.from_dict(obj["displayName"]) if obj.get("displayName") is not None else None,
            "expireWhenRemediationAvailable": obj.get("expireWhenRemediationAvailable"),
            "expiryTime": obj.get("expiryTime"),
            "hash": obj.get("hash"),
            "isObsolete": obj.get("isObsolete"),
            "matcherStrategy": obj.get("matcherStrategy"),
            "noteToReviewer": obj.get("noteToReviewer"),
            "policyId": obj.get("policyId"),
            "policyName": obj.get("policyName"),
            "policyViolationId": obj.get("policyViolationId"),
            "policyWaiverReasonId": obj.get("policyWaiverReasonId"),
            "policyWaiverRequestId": obj.get("policyWaiverRequestId"),
            "reasonText": obj.get("reasonText"),
            "rejectionReason": obj.get("rejectionReason"),
            "requestTime": obj.get("requestTime"),
            "requesterId": obj.get("requesterId"),
            "requesterName": obj.get("requesterName"),
            "reviewerId": obj.get("reviewerId"),
            "reviewerName": obj.get("reviewerName"),
            "scopeOwnerId": obj.get("scopeOwnerId"),
            "scopeOwnerName": obj.get("scopeOwnerName"),
            "scopeOwnerType": obj.get("scopeOwnerType"),
            "status": obj.get("status"),
            "threatLevel": obj.get("threatLevel"),
            "vulnerabilityId": obj.get("vulnerabilityId")
        })
        return _obj


