# coding: utf-8

"""
    Inventory

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from legit_api_client.models.ai_validation_result import AiValidationResult
from legit_api_client.models.closing_reason import ClosingReason
from legit_api_client.models.customer_facing_issue_source_dto import CustomerFacingIssueSourceDto
from legit_api_client.models.dast_confidence_level import DastConfidenceLevel
from legit_api_client.models.dependency_fix_type import DependencyFixType
from legit_api_client.models.issue_closing_location_dto import IssueClosingLocationDto
from legit_api_client.models.issue_comment_dto import IssueCommentDto
from legit_api_client.models.issue_status import IssueStatus
from legit_api_client.models.issue_tag_dto import IssueTagDto
from legit_api_client.models.issue_type import IssueType
from legit_api_client.models.origin_type import OriginType
from legit_api_client.models.secret_issue_validity_status import SecretIssueValidityStatus
from legit_api_client.models.severity import Severity
from legit_api_client.models.snoozed_type import SnoozedType
from typing import Optional, Set
from typing_extensions import Self

class CustomerFacingIssueDto(BaseModel):
    """
    CustomerFacingIssueDto
    """ # noqa: E501
    id: Optional[StrictStr] = None
    title: Optional[StrictStr] = None
    detected_at: Optional[datetime] = Field(default=None, alias="detectedAt")
    last_closed_at: Optional[datetime] = Field(default=None, alias="lastClosedAt")
    last_action_time: Optional[datetime] = Field(default=None, alias="lastActionTime")
    status: Optional[IssueStatus] = None
    issue_type: Optional[IssueType] = Field(default=None, alias="issueType")
    severity: Optional[Severity] = None
    policy_severity: Optional[Severity] = Field(default=None, alias="policySeverity")
    closing_reason: Optional[ClosingReason] = Field(default=None, alias="closingReason")
    closing_location: Optional[IssueClosingLocationDto] = Field(default=None, alias="closingLocation")
    status_changed_note: Optional[StrictStr] = Field(default=None, alias="statusChangedNote")
    remediation_steps: Optional[List[StrictStr]] = Field(default=None, alias="remediationSteps")
    snoozed_type: Optional[SnoozedType] = Field(default=None, alias="snoozedType")
    snoozed_until: Optional[datetime] = Field(default=None, alias="snoozedUntil")
    score: Optional[Union[StrictFloat, StrictInt]] = None
    epss_score: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="epssScore")
    additional_data: Optional[Any] = Field(default=None, description="Additional specific data on the issue (fields can change from issue to issue). This data is not strictly structured and can be changed by legit at any time.", alias="additionalData")
    ai_validation_result: Optional[AiValidationResult] = Field(default=None, alias="aiValidationResult")
    dast_confidence_level: Optional[DastConfidenceLevel] = Field(default=None, alias="dastConfidenceLevel")
    validity_status: Optional[SecretIssueValidityStatus] = Field(default=None, alias="validityStatus")
    validity_check_time: Optional[datetime] = Field(default=None, alias="validityCheckTime")
    verified_validation_url: Optional[StrictStr] = Field(default=None, alias="verifiedValidationUrl")
    minimal_dependency_fix_type: Optional[DependencyFixType] = Field(default=None, alias="minimalDependencyFixType")
    sources: Optional[List[CustomerFacingIssueSourceDto]] = Field(default=None, description="The issue sources. May be omitted if data fetch fails - in this case please contact legit for support.")
    comments: Optional[List[IssueCommentDto]] = Field(default=None, description="Comments on the issue (can be an empty list). May be omitted if data fetch fails - in this case please contact legit for support.")
    tags: Optional[List[IssueTagDto]] = Field(default=None, description="Tags related to the issue (can be an empty list). May be omitted if data fetch fails - in this case please contact legit for support.")
    tickets: Optional[List[StrictStr]] = Field(default=None, description="Tickets related to the issue (can be an empty list). May be omitted if data fetch fails - in this case please contact legit for support.")
    origin_id: Optional[StrictStr] = Field(default=None, alias="originId")
    origin_type: Optional[OriginType] = Field(default=None, alias="originType")
    origin_link: Optional[StrictStr] = Field(default=None, description="A link to fetch the issue origin using the API", alias="originLink")
    action_id: Optional[StrictStr] = Field(default=None, description="The id of the Action that contains this issue", alias="actionId")
    policy_name: Optional[StrictStr] = Field(default=None, alias="policyName")
    product_ids: Optional[List[StrictStr]] = Field(default=None, alias="productIds")
    assigned_user_id: Optional[StrictStr] = Field(default=None, alias="assignedUserId")
    __properties: ClassVar[List[str]] = ["id", "title", "detectedAt", "lastClosedAt", "lastActionTime", "status", "issueType", "severity", "policySeverity", "closingReason", "closingLocation", "statusChangedNote", "remediationSteps", "snoozedType", "snoozedUntil", "score", "epssScore", "additionalData", "aiValidationResult", "dastConfidenceLevel", "validityStatus", "validityCheckTime", "verifiedValidationUrl", "minimalDependencyFixType", "sources", "comments", "tags", "tickets", "originId", "originType", "originLink", "actionId", "policyName", "productIds", "assignedUserId"]

    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 CustomerFacingIssueDto 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.
        """
        excluded_fields: Set[str] = set([
            "additional_data",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in sources (list)
        _items = []
        if self.sources:
            for _item_sources in self.sources:
                if _item_sources:
                    _items.append(_item_sources.to_dict())
            _dict['sources'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in comments (list)
        _items = []
        if self.comments:
            for _item_comments in self.comments:
                if _item_comments:
                    _items.append(_item_comments.to_dict())
            _dict['comments'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['id'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "title": obj.get("title"),
            "detectedAt": obj.get("detectedAt"),
            "lastClosedAt": obj.get("lastClosedAt"),
            "lastActionTime": obj.get("lastActionTime"),
            "status": obj.get("status"),
            "issueType": obj.get("issueType"),
            "severity": obj.get("severity"),
            "policySeverity": obj.get("policySeverity"),
            "closingReason": obj.get("closingReason"),
            "closingLocation": obj.get("closingLocation"),
            "statusChangedNote": obj.get("statusChangedNote"),
            "remediationSteps": obj.get("remediationSteps"),
            "snoozedType": obj.get("snoozedType"),
            "snoozedUntil": obj.get("snoozedUntil"),
            "score": obj.get("score"),
            "epssScore": obj.get("epssScore"),
            "additionalData": obj.get("additionalData"),
            "aiValidationResult": obj.get("aiValidationResult"),
            "dastConfidenceLevel": obj.get("dastConfidenceLevel"),
            "validityStatus": obj.get("validityStatus"),
            "validityCheckTime": obj.get("validityCheckTime"),
            "verifiedValidationUrl": obj.get("verifiedValidationUrl"),
            "minimalDependencyFixType": obj.get("minimalDependencyFixType"),
            "sources": [CustomerFacingIssueSourceDto.from_dict(_item) for _item in obj["sources"]] if obj.get("sources") is not None else None,
            "comments": [IssueCommentDto.from_dict(_item) for _item in obj["comments"]] if obj.get("comments") is not None else None,
            "tags": [IssueTagDto.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "tickets": obj.get("tickets"),
            "originId": obj.get("originId"),
            "originType": obj.get("originType"),
            "originLink": obj.get("originLink"),
            "actionId": obj.get("actionId"),
            "policyName": obj.get("policyName"),
            "productIds": obj.get("productIds"),
            "assignedUserId": obj.get("assignedUserId")
        })
        return _obj


