# 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
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 typing import Optional, Set
from typing_extensions import Self

class MachineAccount(BaseModel):
    """
    MachineAccount
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="System-generated unique ID of the Object")
    name: Optional[StrictStr] = Field(description="Name of the Object")
    created: Optional[datetime] = Field(default=None, description="Creation date of the Object")
    modified: Optional[datetime] = Field(default=None, description="Last modification date of the Object")
    description: Optional[StrictStr] = Field(default=None, description="A description of the machine account")
    native_identity: StrictStr = Field(description="The unique ID of the machine account generated by the source system", alias="nativeIdentity")
    uuid: Optional[StrictStr] = Field(default=None, description="The unique ID of the account as determined by the account schema")
    classification_method: StrictStr = Field(description="Classification Method", alias="classificationMethod")
    machine_identity: Optional[Dict[str, Any]] = Field(default=None, description="The machine identity this account is associated with", alias="machineIdentity")
    owner_identity: Optional[Dict[str, Any]] = Field(default=None, description="The identity who owns this account.", alias="ownerIdentity")
    access_type: Optional[StrictStr] = Field(default=None, description="The connection type of the source this account is from", alias="accessType")
    subtype: Optional[StrictStr] = Field(default=None, description="The sub-type")
    environment: Optional[StrictStr] = Field(default=None, description="Environment")
    attributes: Optional[Dict[str, Any]] = Field(default=None, description="Custom attributes specific to the machine account")
    connector_attributes: Optional[Dict[str, Any]] = Field(description="The connector attributes for the account", alias="connectorAttributes")
    manually_correlated: Optional[StrictBool] = Field(default=False, description="Indicates if the account has been manually correlated to an identity", alias="manuallyCorrelated")
    manually_edited: StrictBool = Field(description="Indicates if the account has been manually edited", alias="manuallyEdited")
    locked: StrictBool = Field(description="Indicates if the account is currently locked")
    enabled: StrictBool = Field(description="Indicates if the account is enabled")
    has_entitlements: StrictBool = Field(description="Indicates if the account has entitlements", alias="hasEntitlements")
    source: Dict[str, Any] = Field(description="The source this machine account belongs to.")
    __properties: ClassVar[List[str]] = ["id", "name", "created", "modified", "description", "nativeIdentity", "uuid", "classificationMethod", "machineIdentity", "ownerIdentity", "accessType", "subtype", "environment", "attributes", "connectorAttributes", "manuallyCorrelated", "manuallyEdited", "locked", "enabled", "hasEntitlements", "source"]

    @field_validator('classification_method')
    def classification_method_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['SOURCE', 'CRITERIA', 'DISCOVERY', 'MANUAL']):
            warnings.warn(f"must be one of enum values ('SOURCE', 'CRITERIA', 'DISCOVERY', 'MANUAL') 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 MachineAccount 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "created",
            "modified",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['name'] = None

        # 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 uuid (nullable) is None
        # and model_fields_set contains the field
        if self.uuid is None and "uuid" in self.model_fields_set:
            _dict['uuid'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of MachineAccount 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"),
            "description": obj.get("description"),
            "nativeIdentity": obj.get("nativeIdentity"),
            "uuid": obj.get("uuid"),
            "classificationMethod": obj.get("classificationMethod"),
            "machineIdentity": obj.get("machineIdentity"),
            "ownerIdentity": obj.get("ownerIdentity"),
            "accessType": obj.get("accessType"),
            "subtype": obj.get("subtype"),
            "environment": obj.get("environment"),
            "attributes": obj.get("attributes"),
            "connectorAttributes": obj.get("connectorAttributes"),
            "manuallyCorrelated": obj.get("manuallyCorrelated") if obj.get("manuallyCorrelated") is not None else False,
            "manuallyEdited": obj.get("manuallyEdited") if obj.get("manuallyEdited") is not None else False,
            "locked": obj.get("locked"),
            "enabled": obj.get("enabled") if obj.get("enabled") is not None else False,
            "hasEntitlements": obj.get("hasEntitlements") if obj.get("hasEntitlements") is not None else True,
            "source": obj.get("source")
        })
        return _obj


