# The Okta software accompanied by this notice is provided pursuant to the following terms:
# Copyright © 2025-Present, Okta, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
# License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
# coding: utf-8

"""
Okta Admin Management

Allows customers to easily access the Okta Management APIs

The version of the OpenAPI document: 5.1.0
Contact: devex-public@okta.com
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from datetime import datetime
from importlib import import_module
from typing import Any, ClassVar, Dict, List, Union
from typing import Optional, Set
from typing import TYPE_CHECKING

from pydantic import BaseModel, ConfigDict, Field, StrictStr

from okta.models.authenticator_key_enum import AuthenticatorKeyEnum
from okta.models.authenticator_links import AuthenticatorLinks
from okta.models.authenticator_type import AuthenticatorType
from okta.models.lifecycle_status import LifecycleStatus

if TYPE_CHECKING:
    from okta.models.authenticator_key_custom_app import AuthenticatorKeyCustomApp
    from okta.models.authenticator_key_duo import AuthenticatorKeyDuo
    from okta.models.authenticator_key_external_idp import AuthenticatorKeyExternalIdp
    from okta.models.authenticator_key_google_otp import AuthenticatorKeyGoogleOtp
    from okta.models.authenticator_key_email import AuthenticatorKeyEmail
    from okta.models.authenticator_key_password import AuthenticatorKeyPassword
    from okta.models.authenticator_key_okta_verify import AuthenticatorKeyOktaVerify
    from okta.models.authenticator_key_onprem import AuthenticatorKeyOnprem
    from okta.models.authenticator_key_phone import AuthenticatorKeyPhone
    from okta.models.authenticator_key_security_key import AuthenticatorKeySecurityKey
    from okta.models.authenticator_key_security_question import (
        AuthenticatorKeySecurityQuestion,
    )
    from okta.models.authenticator_key_smart_card import AuthenticatorKeySmartCard
    from okta.models.authenticator_key_symantec_vip import AuthenticatorKeySymantecVip
    from okta.models.authenticator_key_tac import AuthenticatorKeyTac
    from okta.models.authenticator_key_webauthn import AuthenticatorKeyWebauthn
    from okta.models.authenticator_key_yubikey import AuthenticatorKeyYubikey
    from okta.models.authenticator_simple import AuthenticatorSimple


class AuthenticatorBase(BaseModel):
    """
    AuthenticatorBase
    """  # noqa: E501

    created: Optional[datetime] = Field(
        default=None, description="Timestamp when the authenticator was created"
    )
    id: Optional[StrictStr] = Field(
        default=None, description="A unique identifier for the authenticator"
    )
    key: Optional[AuthenticatorKeyEnum] = None
    last_updated: Optional[datetime] = Field(
        default=None,
        description="Timestamp when the authenticator was last modified",
        alias="lastUpdated",
    )
    name: Optional[StrictStr] = Field(
        default=None, description="Display name of the authenticator"
    )
    status: Optional[LifecycleStatus] = None
    type: Optional[AuthenticatorType] = None
    links: Optional[AuthenticatorLinks] = Field(default=None, alias="_links")
    __properties: ClassVar[List[str]] = [
        "created",
        "id",
        "key",
        "lastUpdated",
        "name",
        "status",
        "type",
        "_links",
    ]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )

    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = "key"

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        "custom_app": "AuthenticatorKeyCustomApp",
        "duo": "AuthenticatorKeyDuo",
        "external_idp": "AuthenticatorKeyExternalIdp",
        "google_otp": "AuthenticatorKeyGoogleOtp",
        "okta_email": "AuthenticatorKeyEmail",
        "okta_password": "AuthenticatorKeyPassword",
        "okta_verify": "AuthenticatorKeyOktaVerify",
        "onprem_mfa": "AuthenticatorKeyOnprem",
        "phone_number": "AuthenticatorKeyPhone",
        "security_key": "AuthenticatorKeySecurityKey",
        "security_question": "AuthenticatorKeySecurityQuestion",
        "smart_card_idp": "AuthenticatorKeySmartCard",
        "symantec_vip": "AuthenticatorKeySymantecVip",
        "tac": "AuthenticatorKeyTac",
        "webauthn": "AuthenticatorKeyWebauthn",
        "yubikey_token": "AuthenticatorKeyYubikey",
        "AuthenticatorSimple": "AuthenticatorSimple",
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj.get(cls.__discriminator_property_name)
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    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[
        Union[
            AuthenticatorKeyCustomApp,
            AuthenticatorKeyDuo,
            AuthenticatorKeyExternalIdp,
            AuthenticatorKeyGoogleOtp,
            AuthenticatorKeyEmail,
            AuthenticatorKeyPassword,
            AuthenticatorKeyOktaVerify,
            AuthenticatorKeyOnprem,
            AuthenticatorKeyPhone,
            AuthenticatorKeySecurityKey,
            AuthenticatorKeySecurityQuestion,
            AuthenticatorKeySmartCard,
            AuthenticatorKeySymantecVip,
            AuthenticatorKeyTac,
            AuthenticatorKeyWebauthn,
            AuthenticatorKeyYubikey,
            AuthenticatorSimple,
        ]
    ]:
        """Create an instance of AuthenticatorBase 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(
            [
                "created",
                "id",
                "last_updated",
            ]
        )

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of links
        if self.links:
            if not isinstance(self.links, dict):
                _dict["_links"] = self.links.to_dict()
            else:
                _dict["_links"] = self.links

        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[
        Union[
            AuthenticatorKeyCustomApp,
            AuthenticatorKeyDuo,
            AuthenticatorKeyExternalIdp,
            AuthenticatorKeyGoogleOtp,
            AuthenticatorKeyEmail,
            AuthenticatorKeyPassword,
            AuthenticatorKeyOktaVerify,
            AuthenticatorKeyOnprem,
            AuthenticatorKeyPhone,
            AuthenticatorKeySecurityKey,
            AuthenticatorKeySecurityQuestion,
            AuthenticatorKeySmartCard,
            AuthenticatorKeySymantecVip,
            AuthenticatorKeyTac,
            AuthenticatorKeyWebauthn,
            AuthenticatorKeyYubikey,
            AuthenticatorSimple,
        ]
    ]:
        """Create an instance of AuthenticatorBase from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        # Import from okta.models to ensure class identity consistency with lazy imports
        models = import_module("okta.models")
        if object_type == "AuthenticatorKeyCustomApp":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyCustomApp.from_dict(obj)
        if object_type == "AuthenticatorKeyDuo":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyDuo.from_dict(obj)
        if object_type == "AuthenticatorKeyExternalIdp":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyExternalIdp.from_dict(obj)
        if object_type == "AuthenticatorKeyGoogleOtp":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyGoogleOtp.from_dict(obj)
        if object_type == "AuthenticatorKeyEmail":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyEmail.from_dict(obj)
        if object_type == "AuthenticatorKeyPassword":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyPassword.from_dict(obj)
        if object_type == "AuthenticatorKeyOktaVerify":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyOktaVerify.from_dict(obj)
        if object_type == "AuthenticatorKeyOnprem":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyOnprem.from_dict(obj)
        if object_type == "AuthenticatorKeyPhone":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyPhone.from_dict(obj)
        if object_type == "AuthenticatorKeySecurityKey":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeySecurityKey.from_dict(obj)
        if object_type == "AuthenticatorKeySecurityQuestion":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeySecurityQuestion.from_dict(obj)
        if object_type == "AuthenticatorKeySmartCard":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeySmartCard.from_dict(obj)
        if object_type == "AuthenticatorKeySymantecVip":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeySymantecVip.from_dict(obj)
        if object_type == "AuthenticatorKeyTac":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyTac.from_dict(obj)
        if object_type == "AuthenticatorKeyWebauthn":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyWebauthn.from_dict(obj)
        if object_type == "AuthenticatorKeyYubikey":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorKeyYubikey.from_dict(obj)
        if object_type == "AuthenticatorSimple":
            # Check if the discriminator maps to the same class to avoid infinite recursion
            if object_type == cls.__name__:
                return cls.model_validate(obj)
            return models.AuthenticatorSimple.from_dict(obj)

        raise ValueError(
            "AuthenticatorBase failed to lookup discriminator value from "
            + json.dumps(obj)
            + ". Discriminator property name: "
            + cls.__discriminator_property_name
            + ", mapping: "
            + json.dumps(cls.__discriminator_value_class_map)
        )
