# 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.approval_config_cron_timezone import ApprovalConfigCronTimezone
from sailpoint.v2025.models.approval_config_escalation_config import ApprovalConfigEscalationConfig
from sailpoint.v2025.models.approval_config_reminder_config import ApprovalConfigReminderConfig
from sailpoint.v2025.models.approval_config_serial_chain_inner import ApprovalConfigSerialChainInner
from sailpoint.v2025.models.approval_config_timeout_config import ApprovalConfigTimeoutConfig
from typing import Optional, Set
from typing_extensions import Self

class ApprovalConfig(BaseModel):
    """
    Approval config Object
    """ # noqa: E501
    tenant_id: Optional[StrictStr] = Field(default=None, description="Tenant ID of the approval configuration.", alias="tenantId")
    id: Optional[StrictStr] = Field(default=None, description="ID of the approval configuration.")
    scope: Optional[StrictStr] = Field(default=None, description="The type/scope of the configuration. Ie DOMAIN_OBJECT, APPROVAL_TYPE, TENANT")
    reminder_config: Optional[ApprovalConfigReminderConfig] = Field(default=None, alias="reminderConfig")
    escalation_config: Optional[ApprovalConfigEscalationConfig] = Field(default=None, alias="escalationConfig")
    timeout_config: Optional[ApprovalConfigTimeoutConfig] = Field(default=None, alias="timeoutConfig")
    cron_timezone: Optional[ApprovalConfigCronTimezone] = Field(default=None, alias="cronTimezone")
    serial_chain: Optional[List[ApprovalConfigSerialChainInner]] = Field(default=None, description="If the approval request has an approvalCriteria of SERIAL this chain will be used to determine the assignment order.", alias="serialChain")
    requires_comment: Optional[StrictStr] = Field(default=None, description="Determines whether a comment is required when approving or rejecting the approval request.", alias="requiresComment")
    fallback_approver: Optional[Dict[str, Any]] = Field(default=None, description="Configuration for fallback approver. Used if the user cannot be found for whatever reason and escalation config does not exist.", alias="fallbackApprover")
    auto_approve: Optional[StrictStr] = Field(default=None, description="OFF will prevent the approval request from being assigned to the requester or requestee by assigning it to their manager instead. DIRECT will cause approval requests to be auto-approved when assigned directly and only to the requester. INDIRECT will auto-approve when the requester appears anywhere in the list of approvers, including in a governance group. This field will only be effective if requestedTarget.reauthRequired is set to false, otherwise the approval will have to be manually approved.", alias="autoApprove")
    __properties: ClassVar[List[str]] = ["tenantId", "id", "scope", "reminderConfig", "escalationConfig", "timeoutConfig", "cronTimezone", "serialChain", "requiresComment", "fallbackApprover", "autoApprove"]

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

        if value not in set(['APPROVAL', 'REJECTION', 'ALL', 'OFF']):
            warnings.warn(f"must be one of enum values ('APPROVAL', 'REJECTION', 'ALL', 'OFF') unknown value: {value}")
        return value

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

        if value not in set(['OFF', 'DIRECT', 'INDIRECT']):
            warnings.warn(f"must be one of enum values ('OFF', 'DIRECT', 'INDIRECT') 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 ApprovalConfig 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 reminder_config
        if self.reminder_config:
            _dict['reminderConfig'] = self.reminder_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of escalation_config
        if self.escalation_config:
            _dict['escalationConfig'] = self.escalation_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of timeout_config
        if self.timeout_config:
            _dict['timeoutConfig'] = self.timeout_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cron_timezone
        if self.cron_timezone:
            _dict['cronTimezone'] = self.cron_timezone.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in serial_chain (list)
        _items = []
        if self.serial_chain:
            for _item_serial_chain in self.serial_chain:
                if _item_serial_chain:
                    _items.append(_item_serial_chain.to_dict())
            _dict['serialChain'] = _items
        # override the default output from pydantic by calling `to_dict()` of fallback_approver
        if self.fallback_approver:
            _dict['fallbackApprover'] = self.fallback_approver.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "tenantId": obj.get("tenantId"),
            "id": obj.get("id"),
            "scope": obj.get("scope"),
            "reminderConfig": ApprovalConfigReminderConfig.from_dict(obj["reminderConfig"]) if obj.get("reminderConfig") is not None else None,
            "escalationConfig": ApprovalConfigEscalationConfig.from_dict(obj["escalationConfig"]) if obj.get("escalationConfig") is not None else None,
            "timeoutConfig": ApprovalConfigTimeoutConfig.from_dict(obj["timeoutConfig"]) if obj.get("timeoutConfig") is not None else None,
            "cronTimezone": ApprovalConfigCronTimezone.from_dict(obj["cronTimezone"]) if obj.get("cronTimezone") is not None else None,
            "serialChain": [ApprovalConfigSerialChainInner.from_dict(_item) for _item in obj["serialChain"]] if obj.get("serialChain") is not None else None,
            "requiresComment": obj.get("requiresComment"),
            "fallbackApprover": ApprovalIdentity.from_dict(obj["fallbackApprover"]) if obj.get("fallbackApprover") is not None else None,
            "autoApprove": obj.get("autoApprove")
        })
        return _obj


