# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from sailpoint.v2025.models.machine_identity_owner_reference import MachineIdentityOwnerReference
from sailpoint.v2025.models.machine_identity_source_reference import MachineIdentitySourceReference
from sailpoint.v2025.models.machine_identity_user_entitlements import MachineIdentityUserEntitlements
from typing import Optional, Set
from typing_extensions import Self

class MachineIdentityUpdatedMachineIdentity(BaseModel):
    """
    Details of the updated machine identity.
    """ # noqa: E501
    id: StrictStr = Field(description="Unique identifier for the machine identity.")
    name: Optional[StrictStr] = Field(default=None, description="Name of the machine identity.")
    created: datetime = Field(description="Creation timestamp.")
    modified: datetime = Field(description="Last modified timestamp.")
    business_application: Optional[StrictStr] = Field(default=None, description="Associated business application.", alias="businessApplication")
    description: Optional[StrictStr] = Field(default=None, description="Description of the machine identity.")
    attributes: Optional[Dict[str, Any]] = Field(default=None, description="The attributes assigned to the identity.")
    subtype: StrictStr = Field(description="Subtype of the machine identity.")
    owners: Optional[List[MachineIdentityOwnerReference]] = Field(default=None, description="List of owners.")
    source_id: Optional[StrictStr] = Field(default=None, description="Source identifier.", alias="sourceId")
    uuid: Optional[StrictStr] = Field(default=None, description="UUID of the machine identity.")
    native_identity: Optional[StrictStr] = Field(default=None, description="Native identity value.", alias="nativeIdentity")
    manually_edited: StrictBool = Field(description="Indicates if manually edited.", alias="manuallyEdited")
    manually_created: Optional[StrictBool] = Field(default=False, description="Indicates if manually created.", alias="manuallyCreated")
    dataset_id: Optional[StrictStr] = Field(default=None, description="Dataset identifier.", alias="datasetId")
    source: Optional[MachineIdentitySourceReference] = None
    user_entitlements: Optional[List[MachineIdentityUserEntitlements]] = Field(default=None, description="List of user entitlements.", alias="userEntitlements")
    exists_on_source: Optional[StrictStr] = Field(default=None, description="Existence status on source.", alias="existsOnSource")
    __properties: ClassVar[List[str]] = ["id", "name", "created", "modified", "businessApplication", "description", "attributes", "subtype", "owners", "sourceId", "uuid", "nativeIdentity", "manuallyEdited", "manuallyCreated", "datasetId", "source", "userEntitlements", "existsOnSource"]

    @field_validator('subtype')
    def subtype_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['AI Agent', 'Application']):
            warnings.warn(f"must be one of enum values ('AI Agent', 'Application') unknown value: {value}")
        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 MachineIdentityUpdatedMachineIdentity 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 owners (list)
        _items = []
        if self.owners:
            for _item_owners in self.owners:
                if _item_owners:
                    _items.append(_item_owners.to_dict())
            _dict['owners'] = _items
        # 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 user_entitlements (list)
        _items = []
        if self.user_entitlements:
            for _item_user_entitlements in self.user_entitlements:
                if _item_user_entitlements:
                    _items.append(_item_user_entitlements.to_dict())
            _dict['userEntitlements'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of MachineIdentityUpdatedMachineIdentity 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"),
            "created": obj.get("created"),
            "modified": obj.get("modified"),
            "businessApplication": obj.get("businessApplication"),
            "description": obj.get("description"),
            "attributes": obj.get("attributes"),
            "subtype": obj.get("subtype"),
            "owners": [MachineIdentityOwnerReference.from_dict(_item) for _item in obj["owners"]] if obj.get("owners") is not None else None,
            "sourceId": obj.get("sourceId"),
            "uuid": obj.get("uuid"),
            "nativeIdentity": obj.get("nativeIdentity"),
            "manuallyEdited": obj.get("manuallyEdited") if obj.get("manuallyEdited") is not None else False,
            "manuallyCreated": obj.get("manuallyCreated") if obj.get("manuallyCreated") is not None else False,
            "datasetId": obj.get("datasetId"),
            "source": MachineIdentitySourceReference.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "userEntitlements": [MachineIdentityUserEntitlements.from_dict(_item) for _item in obj["userEntitlements"]] if obj.get("userEntitlements") is not None else None,
            "existsOnSource": obj.get("existsOnSource")
        })
        return _obj


