# coding: utf-8

"""
    Identity Security Cloud V2024 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: v2024
    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 pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from sailpoint.v2024.models.access_request_post_approval_requested_items_status_inner_approval_info_inner import AccessRequestPostApprovalRequestedItemsStatusInnerApprovalInfoInner
from typing import Optional, Set
from typing_extensions import Self

class AccessRequestPostApprovalRequestedItemsStatusInner(BaseModel):
    """
    AccessRequestPostApprovalRequestedItemsStatusInner
    """ # noqa: E501
    id: StrictStr = Field(description="The unique ID of the access item being requested.")
    name: StrictStr = Field(description="The human friendly name of the access item.")
    description: Optional[StrictStr] = Field(default=None, description="Detailed description of the access item.")
    type: Dict[str, Any] = Field(description="The type of access item.")
    operation: Dict[str, Any] = Field(description="The action to perform on the access item.")
    comment: Optional[StrictStr] = Field(default=None, description="A comment from the identity requesting the access.")
    client_metadata: Optional[Dict[str, Any]] = Field(default=None, description="Additional customer defined metadata about the access item.", alias="clientMetadata")
    approval_info: List[AccessRequestPostApprovalRequestedItemsStatusInnerApprovalInfoInner] = Field(description="A list of one or more approvers for the access request.", alias="approvalInfo")
    __properties: ClassVar[List[str]] = ["id", "name", "description", "type", "operation", "comment", "clientMetadata", "approvalInfo"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['ACCESS_PROFILE', 'ROLE', 'ENTITLEMENT']):
            raise ValueError("must be one of enum values ('ACCESS_PROFILE', 'ROLE', 'ENTITLEMENT')")
        return value

    @field_validator('operation')
    def operation_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['Add', 'Remove']):
            raise ValueError("must be one of enum values ('Add', 'Remove')")
        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 AccessRequestPostApprovalRequestedItemsStatusInner 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 approval_info (list)
        _items = []
        if self.approval_info:
            for _item_approval_info in self.approval_info:
                if _item_approval_info:
                    _items.append(_item_approval_info.to_dict())
            _dict['approvalInfo'] = _items
        # set to None if description (nullable) is None
        # and model_fields_set contains the field
        if self.description is None and "description" in self.model_fields_set:
            _dict['description'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AccessRequestPostApprovalRequestedItemsStatusInner 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"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "type": obj.get("type"),
            "operation": obj.get("operation"),
            "comment": obj.get("comment"),
            "clientMetadata": obj.get("clientMetadata"),
            "approvalInfo": [AccessRequestPostApprovalRequestedItemsStatusInnerApprovalInfoInner.from_dict(_item) for _item in obj["approvalInfo"]] if obj.get("approvalInfo") is not None else None
        })
        return _obj


