# coding: utf-8

"""
    Identity Security Cloud V3 API

    Use these APIs to interact with the Identity Security Cloud platform to achieve repeatable, automated processes with greater scalability. We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs.

    The version of the OpenAPI document: 3.0.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 typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictStr, field_validator
from pydantic import Field
from sailpoint.v3.models.task_result_details_messages_inner import TaskResultDetailsMessagesInner
from sailpoint.v3.models.task_result_details_returns_inner import TaskResultDetailsReturnsInner
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class TaskResultDetails(BaseModel):
    """
    Details about job or task type, state and lifecycle.
    """ # noqa: E501
    type: Optional[StrictStr] = Field(default=None, description="Type of the job or task underlying in the report processing. It could be a quartz task, QPOC or MENTOS jobs or a refresh/sync task.")
    id: Optional[StrictStr] = Field(default=None, description="Unique task definition identifier.")
    report_type: Optional[Dict[str, Any]] = Field(default=None, description="Use this property to define what report should be processed in the RDE service.", alias="reportType")
    description: Optional[StrictStr] = Field(default=None, description="Description of the report purpose and/or contents.")
    parent_name: Optional[StrictStr] = Field(default=None, description="Name of the parent task/report if exists.", alias="parentName")
    launcher: Optional[StrictStr] = Field(default=None, description="Name of the report processing initiator.")
    created: Optional[datetime] = Field(default=None, description="Report creation date")
    launched: Optional[datetime] = Field(default=None, description="Report start date")
    completed: Optional[datetime] = Field(default=None, description="Report completion date")
    completion_status: Optional[StrictStr] = Field(default=None, description="Report completion status.", alias="completionStatus")
    messages: Optional[List[TaskResultDetailsMessagesInner]] = Field(default=None, description="List of the messages dedicated to the report.  From task definition perspective here usually should be warnings or errors.")
    returns: Optional[List[TaskResultDetailsReturnsInner]] = Field(default=None, description="Task definition results, if necessary.")
    attributes: Optional[Dict[str, Dict[str, Any]]] = Field(default=None, description="Extra attributes map(dictionary) needed for the report.")
    progress: Optional[StrictStr] = Field(default=None, description="Current report state.")
    __properties: ClassVar[List[str]] = ["type", "id", "reportType", "description", "parentName", "launcher", "created", "launched", "completed", "completionStatus", "messages", "returns", "attributes", "progress"]

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

        if value not in ('QUARTZ', 'QPOC', 'MENTOS', 'QUEUED_TASK'):
            raise ValueError("must be one of enum values ('QUARTZ', 'QPOC', 'MENTOS', 'QUEUED_TASK')")
        return value

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

        if value not in ('ACCOUNTS', 'IDENTITIES_DETAILS', 'IDENTITIES', 'IDENTITY_PROFILE_IDENTITY_ERROR', 'ORPHAN_IDENTITIES', 'SEARCH_EXPORT', 'UNCORRELATED_ACCOUNTS'):
            raise ValueError("must be one of enum values ('ACCOUNTS', 'IDENTITIES_DETAILS', 'IDENTITIES', 'IDENTITY_PROFILE_IDENTITY_ERROR', 'ORPHAN_IDENTITIES', 'SEARCH_EXPORT', 'UNCORRELATED_ACCOUNTS')")
        return value

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

        if value not in ('SUCCESS', 'WARNING', 'ERROR', 'TERMINATED', 'TEMP_ERROR'):
            raise ValueError("must be one of enum values ('SUCCESS', 'WARNING', 'ERROR', 'TERMINATED', 'TEMP_ERROR')")
        return value

    model_config = {
        "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) -> Self:
        """Create an instance of TaskResultDetails 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in messages (list)
        _items = []
        if self.messages:
            for _item in self.messages:
                if _item:
                    _items.append(_item.to_dict())
            _dict['messages'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in returns (list)
        _items = []
        if self.returns:
            for _item in self.returns:
                if _item:
                    _items.append(_item.to_dict())
            _dict['returns'] = _items
        # set to None if parent_name (nullable) is None
        # and model_fields_set contains the field
        if self.parent_name is None and "parent_name" in self.model_fields_set:
            _dict['parentName'] = None

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of TaskResultDetails from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "id": obj.get("id"),
            "reportType": obj.get("reportType"),
            "description": obj.get("description"),
            "parentName": obj.get("parentName"),
            "launcher": obj.get("launcher"),
            "created": obj.get("created"),
            "launched": obj.get("launched"),
            "completed": obj.get("completed"),
            "completionStatus": obj.get("completionStatus"),
            "messages": [TaskResultDetailsMessagesInner.from_dict(_item) for _item in obj.get("messages")] if obj.get("messages") is not None else None,
            "returns": [TaskResultDetailsReturnsInner.from_dict(_item) for _item in obj.get("returns")] if obj.get("returns") is not None else None,
            "attributes": obj.get("attributes"),
            "progress": obj.get("progress")
        })
        return _obj


