# coding: utf-8

"""
    Identity Security Cloud V2025 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: v2025
    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.v2025.models.base_segment import BaseSegment
from sailpoint.v2025.models.entitlement_document_all_of_manually_updated_fields import EntitlementDocumentAllOfManuallyUpdatedFields
from sailpoint.v2025.models.entitlement_document_all_of_permissions import EntitlementDocumentAllOfPermissions
from sailpoint.v2025.models.entitlement_document_all_of_source import EntitlementDocumentAllOfSource
from typing import Optional, Set
from typing_extensions import Self

class EntitlementDocument(BaseModel):
    """
    Entitlement
    """ # noqa: E501
    id: StrictStr = Field(description="ID of the referenced object.")
    name: StrictStr = Field(description="The human readable name of the referenced object.")
    modified: Optional[datetime] = Field(default=None, description="ISO-8601 date-time referring to the time when the object was last modified.")
    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. ")
    display_name: Optional[StrictStr] = Field(default=None, description="Entitlement's display name.", alias="displayName")
    source: Optional[EntitlementDocumentAllOfSource] = None
    segments: Optional[List[BaseSegment]] = Field(default=None, description="Segments with the entitlement.")
    segment_count: Optional[StrictInt] = Field(default=None, description="Number of segments with the role.", alias="segmentCount")
    requestable: Optional[StrictBool] = Field(default=False, description="Indicates whether the entitlement is requestable.")
    cloud_governed: Optional[StrictBool] = Field(default=False, description="Indicates whether the entitlement is cloud governed.", alias="cloudGoverned")
    created: Optional[datetime] = Field(default=None, description="ISO-8601 date-time referring to the time when the object was created.")
    privileged: Optional[StrictBool] = Field(default=False, description="Indicates whether the entitlement is privileged.")
    tags: Optional[List[StrictStr]] = Field(default=None, description="Tags that have been applied to the object.")
    attribute: Optional[StrictStr] = Field(default=None, description="Attribute information for the entitlement.")
    value: Optional[StrictStr] = Field(default=None, description="Value of the entitlement.")
    source_schema_object_type: Optional[StrictStr] = Field(default=None, description="Source schema object type of the entitlement.", alias="sourceSchemaObjectType")
    var_schema: Optional[StrictStr] = Field(default=None, description="Schema type of the entitlement.", alias="schema")
    hash: Optional[StrictStr] = Field(default=None, description="Read-only calculated hash value of an entitlement.")
    attributes: Optional[Dict[str, Any]] = Field(default=None, description="Attributes of the entitlement.")
    truncated_attributes: Optional[List[StrictStr]] = Field(default=None, description="Truncated attributes of the entitlement.", alias="truncatedAttributes")
    contains_data_access: Optional[StrictBool] = Field(default=False, description="Indicates whether the entitlement contains data access.", alias="containsDataAccess")
    manually_updated_fields: Optional[EntitlementDocumentAllOfManuallyUpdatedFields] = Field(default=None, alias="manuallyUpdatedFields")
    permissions: Optional[List[EntitlementDocumentAllOfPermissions]] = None
    __properties: ClassVar[List[str]] = ["id", "name", "modified", "synced", "displayName", "source", "segments", "segmentCount", "requestable", "cloudGoverned", "created", "privileged", "tags", "attribute", "value", "sourceSchemaObjectType", "schema", "hash", "attributes", "truncatedAttributes", "containsDataAccess", "manuallyUpdatedFields", "permissions"]

    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 EntitlementDocument 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 source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in segments (list)
        _items = []
        if self.segments:
            for _item_segments in self.segments:
                if _item_segments:
                    _items.append(_item_segments.to_dict())
            _dict['segments'] = _items
        # override the default output from pydantic by calling `to_dict()` of manually_updated_fields
        if self.manually_updated_fields:
            _dict['manuallyUpdatedFields'] = self.manually_updated_fields.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in permissions (list)
        _items = []
        if self.permissions:
            for _item_permissions in self.permissions:
                if _item_permissions:
                    _items.append(_item_permissions.to_dict())
            _dict['permissions'] = _items
        # 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 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 manually_updated_fields (nullable) is None
        # and model_fields_set contains the field
        if self.manually_updated_fields is None and "manually_updated_fields" in self.model_fields_set:
            _dict['manuallyUpdatedFields'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of EntitlementDocument 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"),
            "modified": obj.get("modified"),
            "synced": obj.get("synced"),
            "displayName": obj.get("displayName"),
            "source": EntitlementDocumentAllOfSource.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "segments": [BaseSegment.from_dict(_item) for _item in obj["segments"]] if obj.get("segments") is not None else None,
            "segmentCount": obj.get("segmentCount"),
            "requestable": obj.get("requestable") if obj.get("requestable") is not None else False,
            "cloudGoverned": obj.get("cloudGoverned") if obj.get("cloudGoverned") is not None else False,
            "created": obj.get("created"),
            "privileged": obj.get("privileged") if obj.get("privileged") is not None else False,
            "tags": obj.get("tags"),
            "attribute": obj.get("attribute"),
            "value": obj.get("value"),
            "sourceSchemaObjectType": obj.get("sourceSchemaObjectType"),
            "schema": obj.get("schema"),
            "hash": obj.get("hash"),
            "attributes": obj.get("attributes"),
            "truncatedAttributes": obj.get("truncatedAttributes"),
            "containsDataAccess": obj.get("containsDataAccess") if obj.get("containsDataAccess") is not None else False,
            "manuallyUpdatedFields": EntitlementDocumentAllOfManuallyUpdatedFields.from_dict(obj["manuallyUpdatedFields"]) if obj.get("manuallyUpdatedFields") is not None else None,
            "permissions": [EntitlementDocumentAllOfPermissions.from_dict(_item) for _item in obj["permissions"]] if obj.get("permissions") is not None else None
        })
        return _obj


