# 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 typing import Any, ClassVar, Dict, List
from typing import Optional, Set

from pydantic import (
    BaseModel,
    ConfigDict,
    Field,
    StrictBool,
    StrictStr,
    field_validator,
)
from typing_extensions import Self

from okta.models.code_challenge_method import CodeChallengeMethod
from okta.models.endpoint_auth_method import EndpointAuthMethod
from okta.models.grant_type import GrantType
from okta.models.response_mode import ResponseMode
from okta.models.response_types_supported import ResponseTypesSupported
from okta.models.signing_algorithm import SigningAlgorithm
from okta.models.subject_type import SubjectType
from okta.models.token_delivery_mode import TokenDeliveryMode


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

    authorization_endpoint: Optional[StrictStr] = Field(
        default=None,
        description="URL of the authorization server's authorization endpoint.",
    )
    backchannel_authentication_request_signing_alg_values_supported: Optional[
        List[SigningAlgorithm]
    ] = Field(
        default=None,
        description='<x-lifecycle-container><x-lifecycle class="oie"></x-lifecycle></x-lifecycle-container>A list of signing '
        "algorithms that this authorization server supports for signed requests.",
    )
    backchannel_token_delivery_modes_supported: Optional[List[TokenDeliveryMode]] = (
        Field(
            default=None,
            description='<x-lifecycle-container><x-lifecycle class="oie"></x-lifecycle></x-lifecycle-container>The delivery '
            "modes that this authorization server supports for Client-Initiated Backchannel Authentication.",
        )
    )
    claims_supported: Optional[List[StrictStr]] = Field(
        default=None,
        description="A list of the claims supported by this authorization server.",
    )
    code_challenge_methods_supported: Optional[List[CodeChallengeMethod]] = Field(
        default=None,
        description="A list of PKCE code challenge methods supported by this authorization server.",
    )
    device_authorization_endpoint: Optional[StrictStr] = None
    dpop_signing_alg_values_supported: Optional[List[StrictStr]] = Field(
        default=None,
        description="A list of signing algorithms supported by this authorization server for Demonstrating "
        "Proof-of-Possession (DPoP) JWTs.",
    )
    end_session_endpoint: Optional[StrictStr] = Field(
        default=None, description="URL of the authorization server's logout endpoint."
    )
    grant_types_supported: Optional[List[GrantType]] = Field(
        default=None,
        description="A list of the grant type values that this authorization server supports.",
    )
    introspection_endpoint: Optional[StrictStr] = Field(
        default=None,
        description="URL of the authorization server's introspection endpoint.",
    )
    introspection_endpoint_auth_methods_supported: Optional[
        List[EndpointAuthMethod]
    ] = Field(
        default=None,
        description="A list of client authentication methods supported by this introspection endpoint.",
    )
    issuer: Optional[StrictStr] = Field(
        default=None,
        description="The authorization server's issuer identifier. In the context of this document, this is your "
        "authorization server's base URL. This becomes the `iss` claim in an access token.",
    )
    jwks_uri: Optional[StrictStr] = Field(
        default=None,
        description="URL of the authorization server's JSON Web Key Set document.",
    )
    pushed_authorization_request_endpoint: Optional[StrictStr] = None
    registration_endpoint: Optional[StrictStr] = Field(
        default=None,
        description="URL of the authorization server's JSON Web Key Set document.",
    )
    request_object_signing_alg_values_supported: Optional[List[SigningAlgorithm]] = (
        Field(
            default=None,
            description="A list of signing algorithms that this authorization server supports for signed requests.",
        )
    )
    request_parameter_supported: Optional[StrictBool] = Field(
        default=None,
        description="Indicates if Request Parameters are supported by this authorization server.",
    )
    response_modes_supported: Optional[List[ResponseMode]] = Field(
        default=None,
        description="A list of the `response_mode` values that this authorization server supports. More information here.",
    )
    response_types_supported: Optional[List[ResponseTypesSupported]] = Field(
        default=None,
        description="A list of the `response_type` values that this authorization server supports. Can be a combination of "
        "`code`, `token`, and `id_token`.",
    )
    revocation_endpoint: Optional[StrictStr] = Field(
        default=None,
        description="URL of the authorization server's revocation endpoint.",
    )
    revocation_endpoint_auth_methods_supported: Optional[List[EndpointAuthMethod]] = (
        Field(
            default=None,
            description="A list of client authentication methods supported by this revocation endpoint.",
        )
    )
    scopes_supported: Optional[List[StrictStr]] = Field(
        default=None,
        description="A list of the scope values that this authorization server supports.",
    )
    subject_types_supported: Optional[List[SubjectType]] = Field(
        default=None,
        description="A list of the Subject Identifier types that this authorization server supports. Valid types include "
        "`pairwise` and `public`, but only `public` is currently supported. See the [Subject Identifier Types]("
        "https://openid.net/specs/openid-connect-core-1_0.html#SubjectIDTypes) section in the OpenID Connect "
        "specification.",
    )
    token_endpoint: Optional[StrictStr] = Field(
        default=None, description="URL of the authorization server's token endpoint."
    )
    token_endpoint_auth_methods_supported: Optional[List[EndpointAuthMethod]] = Field(
        default=None,
        description="A list of client authentication methods supported by this token endpoint.",
    )
    __properties: ClassVar[List[str]] = [
        "authorization_endpoint",
        "backchannel_authentication_request_signing_alg_values_supported",
        "backchannel_token_delivery_modes_supported",
        "claims_supported",
        "code_challenge_methods_supported",
        "device_authorization_endpoint",
        "dpop_signing_alg_values_supported",
        "end_session_endpoint",
        "grant_types_supported",
        "introspection_endpoint",
        "introspection_endpoint_auth_methods_supported",
        "issuer",
        "jwks_uri",
        "pushed_authorization_request_endpoint",
        "registration_endpoint",
        "request_object_signing_alg_values_supported",
        "request_parameter_supported",
        "response_modes_supported",
        "response_types_supported",
        "revocation_endpoint",
        "revocation_endpoint_auth_methods_supported",
        "scopes_supported",
        "subject_types_supported",
        "token_endpoint",
        "token_endpoint_auth_methods_supported",
    ]

    @field_validator("dpop_signing_alg_values_supported")
    def dpop_signing_alg_values_supported_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set(["ES256", "ES384", "ES512", "RS256", "RS384", "RS512"]):
                raise ValueError(
                    "each list item must be one of ('ES256', 'ES384', 'ES512', 'RS256', 'RS384', 'RS512')"
                )
        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 OAuthMetadata 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,
        )
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "authorization_endpoint": obj.get("authorization_endpoint"),
                "backchannel_authentication_request_signing_alg_values_supported": obj.get(
                    "backchannel_authentication_request_signing_alg_values_supported"
                ),
                "backchannel_token_delivery_modes_supported": obj.get(
                    "backchannel_token_delivery_modes_supported"
                ),
                "claims_supported": obj.get("claims_supported"),
                "code_challenge_methods_supported": obj.get(
                    "code_challenge_methods_supported"
                ),
                "device_authorization_endpoint": obj.get(
                    "device_authorization_endpoint"
                ),
                "dpop_signing_alg_values_supported": obj.get(
                    "dpop_signing_alg_values_supported"
                ),
                "end_session_endpoint": obj.get("end_session_endpoint"),
                "grant_types_supported": obj.get("grant_types_supported"),
                "introspection_endpoint": obj.get("introspection_endpoint"),
                "introspection_endpoint_auth_methods_supported": obj.get(
                    "introspection_endpoint_auth_methods_supported"
                ),
                "issuer": obj.get("issuer"),
                "jwks_uri": obj.get("jwks_uri"),
                "pushed_authorization_request_endpoint": obj.get(
                    "pushed_authorization_request_endpoint"
                ),
                "registration_endpoint": obj.get("registration_endpoint"),
                "request_object_signing_alg_values_supported": obj.get(
                    "request_object_signing_alg_values_supported"
                ),
                "request_parameter_supported": obj.get("request_parameter_supported"),
                "response_modes_supported": obj.get("response_modes_supported"),
                "response_types_supported": obj.get("response_types_supported"),
                "revocation_endpoint": obj.get("revocation_endpoint"),
                "revocation_endpoint_auth_methods_supported": obj.get(
                    "revocation_endpoint_auth_methods_supported"
                ),
                "scopes_supported": obj.get("scopes_supported"),
                "subject_types_supported": obj.get("subject_types_supported"),
                "token_endpoint": obj.get("token_endpoint"),
                "token_endpoint_auth_methods_supported": obj.get(
                    "token_endpoint_auth_methods_supported"
                ),
            }
        )
        return _obj
