# 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 pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from sailpoint.v2025.models.machine_identity_updated_machine_identity import MachineIdentityUpdatedMachineIdentity
from sailpoint.v2025.models.machine_identity_updated_owner_changes import MachineIdentityUpdatedOwnerChanges
from sailpoint.v2025.models.machine_identity_updated_single_value_attribute_changes_inner import MachineIdentityUpdatedSingleValueAttributeChangesInner
from sailpoint.v2025.models.machine_identity_updated_user_entitlement_changes import MachineIdentityUpdatedUserEntitlementChanges
from typing import Optional, Set
from typing_extensions import Self

class MachineIdentityUpdated(BaseModel):
    """
    MachineIdentityUpdated
    """ # noqa: E501
    event_type: StrictStr = Field(description="Type of the event.", alias="eventType")
    machine_identity: MachineIdentityUpdatedMachineIdentity = Field(alias="machineIdentity")
    machine_identity_change_types: List[StrictStr] = Field(description="Types of changes that occurred to the machine identity.", alias="machineIdentityChangeTypes")
    user_entitlement_changes: MachineIdentityUpdatedUserEntitlementChanges = Field(alias="userEntitlementChanges")
    owner_changes: MachineIdentityUpdatedOwnerChanges = Field(alias="ownerChanges")
    single_value_attribute_changes: Optional[List[MachineIdentityUpdatedSingleValueAttributeChangesInner]] = Field(description="Details about the single-value attribute changes that occurred.", alias="singleValueAttributeChanges")
    __properties: ClassVar[List[str]] = ["eventType", "machineIdentity", "machineIdentityChangeTypes", "userEntitlementChanges", "ownerChanges", "singleValueAttributeChanges"]

    @field_validator('event_type')
    def event_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['MACHINE_IDENTITY_UPDATED']):
            warnings.warn(f"must be one of enum values ('MACHINE_IDENTITY_UPDATED') unknown value: {value}")
        return value

    @field_validator('machine_identity_change_types')
    def machine_identity_change_types_validate_enum(cls, value):
        """Validates the enum"""
        for i in value:
            if i not in set(['ATTRIBUTES_CHANGED', 'USER_ENTITLEMENTS_ADDED', 'USER_ENTITLEMENTS_REMOVED', 'OWNERS_ADDED', 'OWNERS_REMOVED']):
                warnings.warn(f"each list item must be one of ('ATTRIBUTES_CHANGED', 'USER_ENTITLEMENTS_ADDED', 'USER_ENTITLEMENTS_REMOVED', 'OWNERS_ADDED', 'OWNERS_REMOVED') unknown value: {i}")
        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 MachineIdentityUpdated 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 machine_identity
        if self.machine_identity:
            _dict['machineIdentity'] = self.machine_identity.to_dict()
        # override the default output from pydantic by calling `to_dict()` of user_entitlement_changes
        if self.user_entitlement_changes:
            _dict['userEntitlementChanges'] = self.user_entitlement_changes.to_dict()
        # override the default output from pydantic by calling `to_dict()` of owner_changes
        if self.owner_changes:
            _dict['ownerChanges'] = self.owner_changes.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in single_value_attribute_changes (list)
        _items = []
        if self.single_value_attribute_changes:
            for _item_single_value_attribute_changes in self.single_value_attribute_changes:
                if _item_single_value_attribute_changes:
                    _items.append(_item_single_value_attribute_changes.to_dict())
            _dict['singleValueAttributeChanges'] = _items
        # set to None if single_value_attribute_changes (nullable) is None
        # and model_fields_set contains the field
        if self.single_value_attribute_changes is None and "single_value_attribute_changes" in self.model_fields_set:
            _dict['singleValueAttributeChanges'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of MachineIdentityUpdated from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "eventType": obj.get("eventType"),
            "machineIdentity": MachineIdentityUpdatedMachineIdentity.from_dict(obj["machineIdentity"]) if obj.get("machineIdentity") is not None else None,
            "machineIdentityChangeTypes": obj.get("machineIdentityChangeTypes"),
            "userEntitlementChanges": MachineIdentityUpdatedUserEntitlementChanges.from_dict(obj["userEntitlementChanges"]) if obj.get("userEntitlementChanges") is not None else None,
            "ownerChanges": MachineIdentityUpdatedOwnerChanges.from_dict(obj["ownerChanges"]) if obj.get("ownerChanges") is not None else None,
            "singleValueAttributeChanges": [MachineIdentityUpdatedSingleValueAttributeChangesInner.from_dict(_item) for _item in obj["singleValueAttributeChanges"]] if obj.get("singleValueAttributeChanges") is not None else None
        })
        return _obj


