# 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


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

    attribute_statements: Optional[StrictStr] = Field(
        default=None,
        description="You can federate user attributes such as Okta profile fields, LDAP, Active Directory, and Workday "
        "values. The SP uses the federated WS-Fed attribute values accordingly.",
        alias="attributeStatements",
    )
    audience_restriction: StrictStr = Field(
        description="The entity ID of the SP. Use the entity ID value exactly as provided by the SP.",
        alias="audienceRestriction",
    )
    authn_context_class_ref: StrictStr = Field(
        description="Identifies the SAML authentication context class for the assertion's authentication statement",
        alias="authnContextClassRef",
    )
    group_filter: Optional[StrictStr] = Field(
        default=None,
        description="A regular expression that filters for the User Groups you want included with the `groupName` attribute. "
        "If the matching User Group has a corresponding AD group, then the attribute statement includes the "
        "value of the attribute specified by `groupValueFormat`. If the matching User Group doesn't contain a "
        "corresponding AD group, then the `groupName` is used in the attribute statement.",
        alias="groupFilter",
    )
    group_name: Optional[StrictStr] = Field(
        default=None,
        description="The group name to include in the WS-Fed response attribute statement. This property is used in "
        "conjunction with the `groupFilter` property.  Groups that are filtered through the `groupFilter` "
        "expression are included with the `groupName` in the attribute statement. Any users that belong to the "
        "group you've filtered are included in the WS-Fed response attribute statement.",
        alias="groupName",
    )
    group_value_format: StrictStr = Field(
        description="Specifies the WS-Fed assertion attribute value for filtered groups. This attribute is only applied to "
        "Active Directory groups.",
        alias="groupValueFormat",
    )
    name_id_format: StrictStr = Field(
        description="The username format that you send in the WS-Fed response",
        alias="nameIDFormat",
    )
    realm: Optional[StrictStr] = Field(
        default=None,
        description="The uniform resource identifier (URI) of the WS-Fed app that's used to share resources securely within "
        "a domain. It's the identity that's sent to the Okta IdP when signing in. See [Realm name]("
        "https://help.okta.com/okta_help.htm?type=oie&id=ext_Apps_Configure_Okta_Template_WS_Federation#Realm).",
    )
    site_url: StrictStr = Field(
        description="Launch URL for the web app", alias="siteURL"
    )
    username_attribute: StrictStr = Field(
        description="Specifies additional username attribute statements to include in the WS-Fed assertion",
        alias="usernameAttribute",
    )
    w_reply_override: Optional[StrictBool] = Field(
        default=None,
        description="Enables a web app to override the `wReplyURL` URL with a reply parameter.",
        alias="wReplyOverride",
    )
    w_reply_url: StrictStr = Field(
        description="The WS-Fed SP endpoint where your users sign in", alias="wReplyURL"
    )
    __properties: ClassVar[List[str]] = [
        "attributeStatements",
        "audienceRestriction",
        "authnContextClassRef",
        "groupFilter",
        "groupName",
        "groupValueFormat",
        "nameIDFormat",
        "realm",
        "siteURL",
        "usernameAttribute",
        "wReplyOverride",
        "wReplyURL",
    ]

    @field_validator("group_value_format")
    def group_value_format_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(["windowsDomainQualifiedName", "samAccountName", "dn"]):
            raise ValueError(
                "must be one of enum values ('windowsDomainQualifiedName', 'samAccountName', 'dn')"
            )
        return value

    @field_validator("username_attribute")
    def username_attribute_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(["username", "upn", "upnAndUsername", "none"]):
            raise ValueError(
                "must be one of enum values ('username', 'upn', 'upnAndUsername', 'none')"
            )
        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 WsFederationApplicationSettingsApplication 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 WsFederationApplicationSettingsApplication from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate(
            {
                "attributeStatements": obj.get("attributeStatements"),
                "audienceRestriction": obj.get("audienceRestriction"),
                "authnContextClassRef": obj.get("authnContextClassRef"),
                "groupFilter": obj.get("groupFilter"),
                "groupName": obj.get("groupName"),
                "groupValueFormat": obj.get("groupValueFormat"),
                "nameIDFormat": obj.get("nameIDFormat"),
                "realm": obj.get("realm"),
                "siteURL": obj.get("siteURL"),
                "usernameAttribute": obj.get("usernameAttribute"),
                "wReplyOverride": obj.get("wReplyOverride"),
                "wReplyURL": obj.get("wReplyURL"),
            }
        )
        return _obj
