# 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
import warnings

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from sailpoint.v3.models.app import App
from sailpoint.v3.models.base_account import BaseAccount
from sailpoint.v3.models.identity_access import IdentityAccess
from sailpoint.v3.models.identity_document_all_of_identity_profile import IdentityDocumentAllOfIdentityProfile
from sailpoint.v3.models.identity_document_all_of_manager import IdentityDocumentAllOfManager
from sailpoint.v3.models.identity_document_all_of_source import IdentityDocumentAllOfSource
from sailpoint.v3.models.owns import Owns
from sailpoint.v3.models.processing_details import ProcessingDetails
from typing import Optional, Set
from typing_extensions import Self

class IdentityDocument(BaseModel):
    """
    Identity
    """ # noqa: E501
    id: StrictStr = Field(description="The unique ID of the referenced object.")
    name: StrictStr = Field(description="The human readable name of the referenced object.")
    display_name: Optional[StrictStr] = Field(default=None, description="Identity's display name.", alias="displayName")
    first_name: Optional[StrictStr] = Field(default=None, description="Identity's first name.", alias="firstName")
    last_name: Optional[StrictStr] = Field(default=None, description="Identity's last name.", alias="lastName")
    email: Optional[StrictStr] = Field(default=None, description="Identity's primary email address.")
    created: Optional[datetime] = Field(default=None, description="ISO-8601 date-time referring to the time when the object was created.")
    modified: Optional[datetime] = Field(default=None, description="ISO-8601 date-time referring to the time when the object was last modified.")
    phone: Optional[StrictStr] = Field(default=None, description="Identity's phone number.")
    synced: Optional[StrictStr] = Field(default=None, description="ISO-8601 date-time referring to the date-time when object was queued to be synced into search database for use in the search API.   This date-time changes anytime there is an update to the object, which triggers a synchronization event being sent to the search database.  There may be some delay between the `synced` time and the time when the updated data is actually available in the search API. ")
    inactive: Optional[StrictBool] = Field(default=False, description="Indicates whether the identity is inactive.")
    protected: Optional[StrictBool] = Field(default=False, description="Indicates whether the identity is protected.")
    status: Optional[StrictStr] = Field(default=None, description="Identity's status in SailPoint.")
    employee_number: Optional[StrictStr] = Field(default=None, description="Identity's employee number.", alias="employeeNumber")
    manager: Optional[IdentityDocumentAllOfManager] = None
    is_manager: Optional[StrictBool] = Field(default=None, description="Indicates whether the identity is a manager of other identities.", alias="isManager")
    identity_profile: Optional[IdentityDocumentAllOfIdentityProfile] = Field(default=None, alias="identityProfile")
    source: Optional[IdentityDocumentAllOfSource] = None
    attributes: Optional[Dict[str, Any]] = Field(default=None, description="Map or dictionary of key/value pairs.")
    disabled: Optional[StrictBool] = Field(default=False, description="Indicates whether the identity is disabled.")
    locked: Optional[StrictBool] = Field(default=False, description="Indicates whether the identity is locked.")
    processing_state: Optional[StrictStr] = Field(default=None, description="Identity's processing state.", alias="processingState")
    processing_details: Optional[ProcessingDetails] = Field(default=None, alias="processingDetails")
    accounts: Optional[List[BaseAccount]] = Field(default=None, description="List of accounts associated with the identity.")
    account_count: Optional[StrictInt] = Field(default=None, description="Number of accounts associated with the identity.", alias="accountCount")
    apps: Optional[List[App]] = Field(default=None, description="List of applications the identity has access to.")
    app_count: Optional[StrictInt] = Field(default=None, description="Number of applications the identity has access to.", alias="appCount")
    access: Optional[List[IdentityAccess]] = Field(default=None, description="List of access items assigned to the identity.")
    access_count: Optional[StrictInt] = Field(default=None, description="Number of access items assigned to the identity.", alias="accessCount")
    entitlement_count: Optional[StrictInt] = Field(default=None, description="Number of entitlements assigned to the identity.", alias="entitlementCount")
    role_count: Optional[StrictInt] = Field(default=None, description="Number of roles assigned to the identity.", alias="roleCount")
    access_profile_count: Optional[StrictInt] = Field(default=None, description="Number of access profiles assigned to the identity.", alias="accessProfileCount")
    owns: Optional[List[Owns]] = Field(default=None, description="Access items the identity owns.")
    owns_count: Optional[StrictInt] = Field(default=None, description="Number of access items the identity owns.", alias="ownsCount")
    tags: Optional[List[StrictStr]] = Field(default=None, description="Tags that have been applied to the object.")
    tags_count: Optional[StrictInt] = Field(default=None, description="Number of tags on the identity.", alias="tagsCount")
    visible_segments: Optional[List[StrictStr]] = Field(default=None, description="List of segments that the identity is in.", alias="visibleSegments")
    visible_segment_count: Optional[StrictInt] = Field(default=None, description="Number of segments the identity is in.", alias="visibleSegmentCount")
    __properties: ClassVar[List[str]] = ["id", "name", "displayName", "firstName", "lastName", "email", "created", "modified", "phone", "synced", "inactive", "protected", "status", "employeeNumber", "manager", "isManager", "identityProfile", "source", "attributes", "disabled", "locked", "processingState", "processingDetails", "accounts", "accountCount", "apps", "appCount", "access", "accessCount", "entitlementCount", "roleCount", "accessProfileCount", "owns", "ownsCount", "tags", "tagsCount", "visibleSegments", "visibleSegmentCount"]

    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 IdentityDocument 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 manager
        if self.manager:
            _dict['manager'] = self.manager.to_dict()
        # override the default output from pydantic by calling `to_dict()` of identity_profile
        if self.identity_profile:
            _dict['identityProfile'] = self.identity_profile.to_dict()
        # override the default output from pydantic by calling `to_dict()` of source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of processing_details
        if self.processing_details:
            _dict['processingDetails'] = self.processing_details.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in accounts (list)
        _items = []
        if self.accounts:
            for _item_accounts in self.accounts:
                if _item_accounts:
                    _items.append(_item_accounts.to_dict())
            _dict['accounts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in apps (list)
        _items = []
        if self.apps:
            for _item_apps in self.apps:
                if _item_apps:
                    _items.append(_item_apps.to_dict())
            _dict['apps'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in access (list)
        _items = []
        if self.access:
            for _item_access in self.access:
                if _item_access:
                    _items.append(_item_access.to_dict())
            _dict['access'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in owns (list)
        _items = []
        if self.owns:
            for _item_owns in self.owns:
                if _item_owns:
                    _items.append(_item_owns.to_dict())
            _dict['owns'] = _items
        # set to None if created (nullable) is None
        # and model_fields_set contains the field
        if self.created is None and "created" in self.model_fields_set:
            _dict['created'] = 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 manager (nullable) is None
        # and model_fields_set contains the field
        if self.manager is None and "manager" in self.model_fields_set:
            _dict['manager'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of IdentityDocument 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"),
            "displayName": obj.get("displayName"),
            "firstName": obj.get("firstName"),
            "lastName": obj.get("lastName"),
            "email": obj.get("email"),
            "created": obj.get("created"),
            "modified": obj.get("modified"),
            "phone": obj.get("phone"),
            "synced": obj.get("synced"),
            "inactive": obj.get("inactive") if obj.get("inactive") is not None else False,
            "protected": obj.get("protected") if obj.get("protected") is not None else False,
            "status": obj.get("status"),
            "employeeNumber": obj.get("employeeNumber"),
            "manager": IdentityDocumentAllOfManager.from_dict(obj["manager"]) if obj.get("manager") is not None else None,
            "isManager": obj.get("isManager"),
            "identityProfile": IdentityDocumentAllOfIdentityProfile.from_dict(obj["identityProfile"]) if obj.get("identityProfile") is not None else None,
            "source": IdentityDocumentAllOfSource.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "attributes": obj.get("attributes"),
            "disabled": obj.get("disabled") if obj.get("disabled") is not None else False,
            "locked": obj.get("locked") if obj.get("locked") is not None else False,
            "processingState": obj.get("processingState"),
            "processingDetails": ProcessingDetails.from_dict(obj["processingDetails"]) if obj.get("processingDetails") is not None else None,
            "accounts": [BaseAccount.from_dict(_item) for _item in obj["accounts"]] if obj.get("accounts") is not None else None,
            "accountCount": obj.get("accountCount"),
            "apps": [App.from_dict(_item) for _item in obj["apps"]] if obj.get("apps") is not None else None,
            "appCount": obj.get("appCount"),
            "access": [IdentityAccess.from_dict(_item) for _item in obj["access"]] if obj.get("access") is not None else None,
            "accessCount": obj.get("accessCount"),
            "entitlementCount": obj.get("entitlementCount"),
            "roleCount": obj.get("roleCount"),
            "accessProfileCount": obj.get("accessProfileCount"),
            "owns": [Owns.from_dict(_item) for _item in obj["owns"]] if obj.get("owns") is not None else None,
            "ownsCount": obj.get("ownsCount"),
            "tags": obj.get("tags"),
            "tagsCount": obj.get("tagsCount"),
            "visibleSegments": obj.get("visibleSegments"),
            "visibleSegmentCount": obj.get("visibleSegmentCount")
        })
        return _obj


