# coding: utf-8

"""
    Identity Security Cloud Beta API

    Use these APIs to interact with the Identity Security Cloud platform to achieve repeatable, automated processes with greater scalability. These APIs are in beta and are subject to change. 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.1.0-beta
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from sailpoint.beta.models.approval_item_details import ApprovalItemDetails
from sailpoint.beta.models.form_details import FormDetails
from sailpoint.beta.models.remediation_item_details import RemediationItemDetails
from sailpoint.beta.models.work_item_state import WorkItemState
from sailpoint.beta.models.work_item_type import WorkItemType
from typing import Optional, Set
from typing_extensions import Self

class WorkItems(BaseModel):
    """
    WorkItems
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="ID of the work item")
    requester_id: Optional[StrictStr] = Field(default=None, description="ID of the requester", alias="requesterId")
    requester_display_name: Optional[StrictStr] = Field(default=None, description="The displayname of the requester", alias="requesterDisplayName")
    owner_id: Optional[StrictStr] = Field(default=None, description="The ID of the owner", alias="ownerId")
    owner_name: Optional[StrictStr] = Field(default=None, description="The name of the owner", alias="ownerName")
    created: Optional[datetime] = None
    modified: Optional[datetime] = None
    description: Optional[StrictStr] = Field(default=None, description="The description of the work item")
    state: Optional[WorkItemState] = None
    type: Optional[WorkItemType] = None
    remediation_items: Optional[List[RemediationItemDetails]] = Field(default=None, alias="remediationItems")
    approval_items: Optional[List[ApprovalItemDetails]] = Field(default=None, alias="approvalItems")
    name: Optional[StrictStr] = Field(default=None, description="The work item name")
    completed: Optional[datetime] = None
    num_items: Optional[StrictInt] = Field(default=None, description="The number of items in the work item", alias="numItems")
    errors: Optional[List[StrictStr]] = None
    form: Optional[FormDetails] = None
    __properties: ClassVar[List[str]] = ["id", "requesterId", "requesterDisplayName", "ownerId", "ownerName", "created", "modified", "description", "state", "type", "remediationItems", "approvalItems", "name", "completed", "numItems", "errors", "form"]

    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 WorkItems 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 each item in remediation_items (list)
        _items = []
        if self.remediation_items:
            for _item_remediation_items in self.remediation_items:
                if _item_remediation_items:
                    _items.append(_item_remediation_items.to_dict())
            _dict['remediationItems'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in approval_items (list)
        _items = []
        if self.approval_items:
            for _item_approval_items in self.approval_items:
                if _item_approval_items:
                    _items.append(_item_approval_items.to_dict())
            _dict['approvalItems'] = _items
        # override the default output from pydantic by calling `to_dict()` of form
        if self.form:
            _dict['form'] = self.form.to_dict()
        # set to None if requester_id (nullable) is None
        # and model_fields_set contains the field
        if self.requester_id is None and "requester_id" in self.model_fields_set:
            _dict['requesterId'] = None

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

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

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

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

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

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

        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['name'] = 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 num_items (nullable) is None
        # and model_fields_set contains the field
        if self.num_items is None and "num_items" in self.model_fields_set:
            _dict['numItems'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of WorkItems 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"),
            "requesterId": obj.get("requesterId"),
            "requesterDisplayName": obj.get("requesterDisplayName"),
            "ownerId": obj.get("ownerId"),
            "ownerName": obj.get("ownerName"),
            "created": obj.get("created"),
            "modified": obj.get("modified"),
            "description": obj.get("description"),
            "state": obj.get("state"),
            "type": obj.get("type"),
            "remediationItems": [RemediationItemDetails.from_dict(_item) for _item in obj["remediationItems"]] if obj.get("remediationItems") is not None else None,
            "approvalItems": [ApprovalItemDetails.from_dict(_item) for _item in obj["approvalItems"]] if obj.get("approvalItems") is not None else None,
            "name": obj.get("name"),
            "completed": obj.get("completed"),
            "numItems": obj.get("numItems"),
            "errors": obj.get("errors"),
            "form": FormDetails.from_dict(obj["form"]) if obj.get("form") is not None else None
        })
        return _obj


