# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from sailpoint.v2025.models.source_account_correlation_config import SourceAccountCorrelationConfig
from sailpoint.v2025.models.source_account_correlation_rule import SourceAccountCorrelationRule
from sailpoint.v2025.models.source_before_provisioning_rule import SourceBeforeProvisioningRule
from sailpoint.v2025.models.source_cluster import SourceCluster
from sailpoint.v2025.models.source_management_workgroup import SourceManagementWorkgroup
from sailpoint.v2025.models.source_manager_correlation_mapping import SourceManagerCorrelationMapping
from sailpoint.v2025.models.source_manager_correlation_rule import SourceManagerCorrelationRule
from sailpoint.v2025.models.source_owner import SourceOwner
from sailpoint.v2025.models.source_password_policies_inner import SourcePasswordPoliciesInner
from sailpoint.v2025.models.source_schemas_inner import SourceSchemasInner
from typing import Optional, Set
from typing_extensions import Self

class Source(BaseModel):
    """
    Source
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="Source ID.")
    name: StrictStr = Field(description="Source's human-readable name.")
    description: Optional[StrictStr] = Field(default=None, description="Source's human-readable description.")
    owner: SourceOwner
    cluster: Optional[SourceCluster] = None
    account_correlation_config: Optional[SourceAccountCorrelationConfig] = Field(default=None, alias="accountCorrelationConfig")
    account_correlation_rule: Optional[SourceAccountCorrelationRule] = Field(default=None, alias="accountCorrelationRule")
    manager_correlation_mapping: Optional[SourceManagerCorrelationMapping] = Field(default=None, alias="managerCorrelationMapping")
    manager_correlation_rule: Optional[SourceManagerCorrelationRule] = Field(default=None, alias="managerCorrelationRule")
    before_provisioning_rule: Optional[SourceBeforeProvisioningRule] = Field(default=None, alias="beforeProvisioningRule")
    schemas: Optional[List[SourceSchemasInner]] = Field(default=None, description="List of references to schema objects.")
    password_policies: Optional[List[SourcePasswordPoliciesInner]] = Field(default=None, description="List of references to the associated PasswordPolicy objects.", alias="passwordPolicies")
    features: Optional[List[StrictStr]] = Field(default=None, description="Optional features that can be supported by a source. Modifying the features array may cause source configuration errors that are unsupportable. It is recommended to not modify this array for SailPoint supported connectors. * AUTHENTICATE: The source supports pass-through authentication. * COMPOSITE: The source supports composite source creation. * DIRECT_PERMISSIONS: The source supports returning DirectPermissions. * DISCOVER_SCHEMA: The source supports discovering schemas for users and groups. * ENABLE The source supports reading if an account is enabled or disabled. * MANAGER_LOOKUP: The source supports looking up managers as they are encountered in a feed. This is the opposite of NO_RANDOM_ACCESS. * NO_RANDOM_ACCESS: The source does not support random access and the getObject() methods should not be called and expected to perform. * PROXY: The source can serve as a proxy for another source. When an source has a proxy, all connector calls made with that source are redirected through the connector for the proxy source. * SEARCH * TEMPLATE * UNLOCK: The source supports reading if an account is locked or unlocked. * UNSTRUCTURED_TARGETS: The source supports returning unstructured Targets. * SHAREPOINT_TARGET: The source supports returning unstructured Target data for SharePoint. It will be typically used by AD, LDAP sources. * PROVISIONING: The source can both read and write accounts. Having this feature implies that the provision() method is implemented. It also means that direct and target permissions can also be provisioned if they can be returned by aggregation. * GROUP_PROVISIONING: The source can both read and write groups. Having this feature implies that the provision() method is implemented. * SYNC_PROVISIONING: The source can provision accounts synchronously. * PASSWORD: The source can provision password changes. Since sources can never read passwords, this is should only be used in conjunction with the PROVISIONING feature. * CURRENT_PASSWORD: Some source types support verification of the current password * ACCOUNT_ONLY_REQUEST: The source supports requesting accounts without entitlements. * ADDITIONAL_ACCOUNT_REQUEST: The source supports requesting additional accounts. * NO_AGGREGATION: A source that does not support aggregation. * GROUPS_HAVE_MEMBERS: The source models group memberships with a member attribute on the group object rather than a groups attribute on the account object. This effects the implementation of delta account aggregation. * NO_PERMISSIONS_PROVISIONING: Indicates that the connector cannot provision direct or target permissions for accounts. When DIRECT_PERMISSIONS and PROVISIONING features are present, it is assumed that the connector can also provision direct permissions. This feature disables that assumption and causes permission request to be converted to work items for accounts. * NO_GROUP_PERMISSIONS_PROVISIONING: Indicates that the connector cannot provision direct or target permissions for groups. When DIRECT_PERMISSIONS and PROVISIONING features are present, it is assumed that the connector can also provision direct permissions. This feature disables that assumption and causes permission request to be converted to work items for groups. * NO_UNSTRUCTURED_TARGETS_PROVISIONING: This string will be replaced by NO_GROUP_PERMISSIONS_PROVISIONING and NO_PERMISSIONS_PROVISIONING. * NO_DIRECT_PERMISSIONS_PROVISIONING: This string will be replaced by NO_GROUP_PERMISSIONS_PROVISIONING and NO_PERMISSIONS_PROVISIONING. * USES_UUID: Connectivity 2.0 flag used to indicate that the connector supports a compound naming structure. * PREFER_UUID: Used in ISC Provisioning AND Aggregation to decide if it should prefer account.uuid to account.nativeIdentity when data is read in through aggregation OR pushed out through provisioning. * ARM_SECURITY_EXTRACT: Indicates the application supports Security extracts for ARM * ARM_UTILIZATION_EXTRACT: Indicates the application supports Utilization extracts for ARM * ARM_CHANGELOG_EXTRACT: Indicates the application supports Change-log extracts for ARM")
    type: Optional[StrictStr] = Field(default=None, description="Specifies the type of system being managed e.g. Active Directory, Workday, etc.. If you are creating a delimited file source, you must set the `provisionasCsv` query parameter to `true`. ")
    connector: StrictStr = Field(description="Connector script name.")
    connector_class: Optional[StrictStr] = Field(default=None, description="Fully qualified name of the Java class that implements the connector interface.", alias="connectorClass")
    connector_attributes: Optional[Dict[str, Any]] = Field(default=None, description="Connector specific configuration. This configuration will differ from type to type.", alias="connectorAttributes")
    delete_threshold: Optional[StrictInt] = Field(default=None, description="Number from 0 to 100 that specifies when to skip the delete phase.", alias="deleteThreshold")
    authoritative: Optional[StrictBool] = Field(default=False, description="When this is true, it indicates that the source is referenced by an identity profile.")
    management_workgroup: Optional[SourceManagementWorkgroup] = Field(default=None, alias="managementWorkgroup")
    healthy: Optional[StrictBool] = Field(default=False, description="When this is true, it indicates that the source is healthy.")
    status: Optional[StrictStr] = Field(default=None, description="Status identifier that gives specific information about why a source is or isn't healthy. ")
    since: Optional[StrictStr] = Field(default=None, description="Timestamp that shows when a source health check was last performed.")
    connector_id: Optional[StrictStr] = Field(default=None, description="Connector ID", alias="connectorId")
    connector_name: Optional[StrictStr] = Field(default=None, description="Name of the connector that was chosen during source creation.", alias="connectorName")
    connection_type: Optional[StrictStr] = Field(default=None, description="Type of connection (direct or file).", alias="connectionType")
    connector_implementation_id: Optional[StrictStr] = Field(default=None, description="Connector implementation ID.", alias="connectorImplementationId")
    created: Optional[datetime] = Field(default=None, description="Date-time when the source was created")
    modified: Optional[datetime] = Field(default=None, description="Date-time when the source was last modified.")
    credential_provider_enabled: Optional[StrictBool] = Field(default=False, description="If this is true, it enables a credential provider for the source. If credentialProvider is turned on,  then the source can use credential provider(s) to fetch credentials.", alias="credentialProviderEnabled")
    category: Optional[StrictStr] = Field(default=None, description="Source category (e.g. null, CredentialProvider).")
    __properties: ClassVar[List[str]] = ["id", "name", "description", "owner", "cluster", "accountCorrelationConfig", "accountCorrelationRule", "managerCorrelationMapping", "managerCorrelationRule", "beforeProvisioningRule", "schemas", "passwordPolicies", "features", "type", "connector", "connectorClass", "connectorAttributes", "deleteThreshold", "authoritative", "managementWorkgroup", "healthy", "status", "since", "connectorId", "connectorName", "connectionType", "connectorImplementationId", "created", "modified", "credentialProviderEnabled", "category"]

    @field_validator('features')
    def features_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set(['AUTHENTICATE', 'COMPOSITE', 'DIRECT_PERMISSIONS', 'DISCOVER_SCHEMA', 'ENABLE', 'MANAGER_LOOKUP', 'NO_RANDOM_ACCESS', 'PROXY', 'SEARCH', 'TEMPLATE', 'UNLOCK', 'UNSTRUCTURED_TARGETS', 'SHAREPOINT_TARGET', 'PROVISIONING', 'GROUP_PROVISIONING', 'SYNC_PROVISIONING', 'PASSWORD', 'CURRENT_PASSWORD', 'ACCOUNT_ONLY_REQUEST', 'ADDITIONAL_ACCOUNT_REQUEST', 'NO_AGGREGATION', 'GROUPS_HAVE_MEMBERS', 'NO_PERMISSIONS_PROVISIONING', 'NO_GROUP_PERMISSIONS_PROVISIONING', 'NO_UNSTRUCTURED_TARGETS_PROVISIONING', 'NO_DIRECT_PERMISSIONS_PROVISIONING', 'PREFER_UUID', 'ARM_SECURITY_EXTRACT', 'ARM_UTILIZATION_EXTRACT', 'ARM_CHANGELOG_EXTRACT', 'USES_UUID', 'APPLICATION_DISCOVERY']):
                warnings.warn(f"each list item must be one of ('AUTHENTICATE', 'COMPOSITE', 'DIRECT_PERMISSIONS', 'DISCOVER_SCHEMA', 'ENABLE', 'MANAGER_LOOKUP', 'NO_RANDOM_ACCESS', 'PROXY', 'SEARCH', 'TEMPLATE', 'UNLOCK', 'UNSTRUCTURED_TARGETS', 'SHAREPOINT_TARGET', 'PROVISIONING', 'GROUP_PROVISIONING', 'SYNC_PROVISIONING', 'PASSWORD', 'CURRENT_PASSWORD', 'ACCOUNT_ONLY_REQUEST', 'ADDITIONAL_ACCOUNT_REQUEST', 'NO_AGGREGATION', 'GROUPS_HAVE_MEMBERS', 'NO_PERMISSIONS_PROVISIONING', 'NO_GROUP_PERMISSIONS_PROVISIONING', 'NO_UNSTRUCTURED_TARGETS_PROVISIONING', 'NO_DIRECT_PERMISSIONS_PROVISIONING', 'PREFER_UUID', 'ARM_SECURITY_EXTRACT', 'ARM_UTILIZATION_EXTRACT', 'ARM_CHANGELOG_EXTRACT', 'USES_UUID', 'APPLICATION_DISCOVERY') unknown value: {i}")
        return value

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['SOURCE_STATE_ERROR_ACCOUNT_FILE_IMPORT', 'SOURCE_STATE_ERROR_CLUSTER', 'SOURCE_STATE_ERROR_SOURCE', 'SOURCE_STATE_ERROR_VA', 'SOURCE_STATE_FAILURE_CLUSTER', 'SOURCE_STATE_FAILURE_SOURCE', 'SOURCE_STATE_HEALTHY', 'SOURCE_STATE_UNCHECKED_CLUSTER', 'SOURCE_STATE_UNCHECKED_CLUSTER_NO_SOURCES', 'SOURCE_STATE_UNCHECKED_SOURCE', 'SOURCE_STATE_UNCHECKED_SOURCE_NO_ACCOUNTS']):
            warnings.warn(f"must be one of enum values ('SOURCE_STATE_ERROR_ACCOUNT_FILE_IMPORT', 'SOURCE_STATE_ERROR_CLUSTER', 'SOURCE_STATE_ERROR_SOURCE', 'SOURCE_STATE_ERROR_VA', 'SOURCE_STATE_FAILURE_CLUSTER', 'SOURCE_STATE_FAILURE_SOURCE', 'SOURCE_STATE_HEALTHY', 'SOURCE_STATE_UNCHECKED_CLUSTER', 'SOURCE_STATE_UNCHECKED_CLUSTER_NO_SOURCES', 'SOURCE_STATE_UNCHECKED_SOURCE', 'SOURCE_STATE_UNCHECKED_SOURCE_NO_ACCOUNTS') 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 Source 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.
        """
        excluded_fields: Set[str] = set([
            "id",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of owner
        if self.owner:
            _dict['owner'] = self.owner.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cluster
        if self.cluster:
            _dict['cluster'] = self.cluster.to_dict()
        # override the default output from pydantic by calling `to_dict()` of account_correlation_config
        if self.account_correlation_config:
            _dict['accountCorrelationConfig'] = self.account_correlation_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of account_correlation_rule
        if self.account_correlation_rule:
            _dict['accountCorrelationRule'] = self.account_correlation_rule.to_dict()
        # override the default output from pydantic by calling `to_dict()` of manager_correlation_mapping
        if self.manager_correlation_mapping:
            _dict['managerCorrelationMapping'] = self.manager_correlation_mapping.to_dict()
        # override the default output from pydantic by calling `to_dict()` of manager_correlation_rule
        if self.manager_correlation_rule:
            _dict['managerCorrelationRule'] = self.manager_correlation_rule.to_dict()
        # override the default output from pydantic by calling `to_dict()` of before_provisioning_rule
        if self.before_provisioning_rule:
            _dict['beforeProvisioningRule'] = self.before_provisioning_rule.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in schemas (list)
        _items = []
        if self.schemas:
            for _item_schemas in self.schemas:
                if _item_schemas:
                    _items.append(_item_schemas.to_dict())
            _dict['schemas'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in password_policies (list)
        _items = []
        if self.password_policies:
            for _item_password_policies in self.password_policies:
                if _item_password_policies:
                    _items.append(_item_password_policies.to_dict())
            _dict['passwordPolicies'] = _items
        # override the default output from pydantic by calling `to_dict()` of management_workgroup
        if self.management_workgroup:
            _dict['managementWorkgroup'] = self.management_workgroup.to_dict()
        # set to None if cluster (nullable) is None
        # and model_fields_set contains the field
        if self.cluster is None and "cluster" in self.model_fields_set:
            _dict['cluster'] = None

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Source 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"),
            "description": obj.get("description"),
            "owner": SourceOwner.from_dict(obj["owner"]) if obj.get("owner") is not None else None,
            "cluster": SourceCluster.from_dict(obj["cluster"]) if obj.get("cluster") is not None else None,
            "accountCorrelationConfig": SourceAccountCorrelationConfig.from_dict(obj["accountCorrelationConfig"]) if obj.get("accountCorrelationConfig") is not None else None,
            "accountCorrelationRule": SourceAccountCorrelationRule.from_dict(obj["accountCorrelationRule"]) if obj.get("accountCorrelationRule") is not None else None,
            "managerCorrelationMapping": SourceManagerCorrelationMapping.from_dict(obj["managerCorrelationMapping"]) if obj.get("managerCorrelationMapping") is not None else None,
            "managerCorrelationRule": SourceManagerCorrelationRule.from_dict(obj["managerCorrelationRule"]) if obj.get("managerCorrelationRule") is not None else None,
            "beforeProvisioningRule": SourceBeforeProvisioningRule.from_dict(obj["beforeProvisioningRule"]) if obj.get("beforeProvisioningRule") is not None else None,
            "schemas": [SourceSchemasInner.from_dict(_item) for _item in obj["schemas"]] if obj.get("schemas") is not None else None,
            "passwordPolicies": [SourcePasswordPoliciesInner.from_dict(_item) for _item in obj["passwordPolicies"]] if obj.get("passwordPolicies") is not None else None,
            "features": obj.get("features"),
            "type": obj.get("type"),
            "connector": obj.get("connector"),
            "connectorClass": obj.get("connectorClass"),
            "connectorAttributes": obj.get("connectorAttributes"),
            "deleteThreshold": obj.get("deleteThreshold"),
            "authoritative": obj.get("authoritative") if obj.get("authoritative") is not None else False,
            "managementWorkgroup": SourceManagementWorkgroup.from_dict(obj["managementWorkgroup"]) if obj.get("managementWorkgroup") is not None else None,
            "healthy": obj.get("healthy") if obj.get("healthy") is not None else False,
            "status": obj.get("status"),
            "since": obj.get("since"),
            "connectorId": obj.get("connectorId"),
            "connectorName": obj.get("connectorName"),
            "connectionType": obj.get("connectionType"),
            "connectorImplementationId": obj.get("connectorImplementationId"),
            "created": obj.get("created"),
            "modified": obj.get("modified"),
            "credentialProviderEnabled": obj.get("credentialProviderEnabled") if obj.get("credentialProviderEnabled") is not None else False,
            "category": obj.get("category")
        })
        return _obj


