# 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
from typing_extensions import Self

from okta.models.acs_endpoint import AcsEndpoint
from okta.models.saml_attribute_statement import SamlAttributeStatement
from okta.models.sign_on_inline_hook import SignOnInlineHook
from okta.models.single_logout import SingleLogout
from okta.models.slo_participate import SloParticipate
from okta.models.sp_certificate import SpCertificate


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

    acs_endpoints: Optional[List[AcsEndpoint]] = Field(
        default=None, alias="acsEndpoints"
    )
    allow_multiple_acs_endpoints: Optional[StrictBool] = Field(
        default=None, alias="allowMultipleAcsEndpoints"
    )
    assertion_signed: Optional[StrictBool] = Field(
        default=None, alias="assertionSigned"
    )
    attribute_statements: Optional[List[SamlAttributeStatement]] = Field(
        default=None, alias="attributeStatements"
    )
    audience: Optional[StrictStr] = None
    audience_override: Optional[StrictStr] = Field(
        default=None, alias="audienceOverride"
    )
    authn_context_class_ref: Optional[StrictStr] = Field(
        default=None, alias="authnContextClassRef"
    )
    configured_attribute_statements: Optional[List[SamlAttributeStatement]] = Field(
        default=None, alias="configuredAttributeStatements"
    )
    default_relay_state: Optional[StrictStr] = Field(
        default=None, alias="defaultRelayState"
    )
    destination: Optional[StrictStr] = None
    destination_override: Optional[StrictStr] = Field(
        default=None, alias="destinationOverride"
    )
    digest_algorithm: Optional[StrictStr] = Field(default=None, alias="digestAlgorithm")
    honor_force_authn: Optional[StrictBool] = Field(
        default=None, alias="honorForceAuthn"
    )
    idp_issuer: Optional[StrictStr] = Field(default=None, alias="idpIssuer")
    inline_hooks: Optional[List[SignOnInlineHook]] = Field(
        default=None, alias="inlineHooks"
    )
    participate_slo: Optional[SloParticipate] = Field(
        default=None, alias="participateSlo"
    )
    recipient: Optional[StrictStr] = None
    recipient_override: Optional[StrictStr] = Field(
        default=None, alias="recipientOverride"
    )
    request_compressed: Optional[StrictBool] = Field(
        default=None, alias="requestCompressed"
    )
    response_signed: Optional[StrictBool] = Field(default=None, alias="responseSigned")
    signature_algorithm: Optional[StrictStr] = Field(
        default=None, alias="signatureAlgorithm"
    )
    slo: Optional[SingleLogout] = None
    sp_certificate: Optional[SpCertificate] = Field(default=None, alias="spCertificate")
    sp_issuer: Optional[StrictStr] = Field(default=None, alias="spIssuer")
    sso_acs_url: Optional[StrictStr] = Field(default=None, alias="ssoAcsUrl")
    sso_acs_url_override: Optional[StrictStr] = Field(
        default=None, alias="ssoAcsUrlOverride"
    )
    subject_name_id_format: Optional[StrictStr] = Field(
        default=None, alias="subjectNameIdFormat"
    )
    subject_name_id_template: Optional[StrictStr] = Field(
        default=None, alias="subjectNameIdTemplate"
    )
    __properties: ClassVar[List[str]] = [
        "acsEndpoints",
        "allowMultipleAcsEndpoints",
        "assertionSigned",
        "attributeStatements",
        "audience",
        "audienceOverride",
        "authnContextClassRef",
        "configuredAttributeStatements",
        "defaultRelayState",
        "destination",
        "destinationOverride",
        "digestAlgorithm",
        "honorForceAuthn",
        "idpIssuer",
        "inlineHooks",
        "participateSlo",
        "recipient",
        "recipientOverride",
        "requestCompressed",
        "responseSigned",
        "signatureAlgorithm",
        "slo",
        "spCertificate",
        "spIssuer",
        "ssoAcsUrl",
        "ssoAcsUrlOverride",
        "subjectNameIdFormat",
        "subjectNameIdTemplate",
    ]

    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 SamlApplicationSettingsSignOn 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 each item in acs_endpoints (list)
        _items = []
        if self.acs_endpoints:
            for _item in self.acs_endpoints:
                if _item:
                    _items.append(_item.to_dict())
            _dict["acsEndpoints"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in attribute_statements (list)
        _items = []
        if self.attribute_statements:
            for _item in self.attribute_statements:
                if _item:
                    _items.append(_item.to_dict())
            _dict["attributeStatements"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in configured_attribute_statements
        # (list)
        _items = []
        if self.configured_attribute_statements:
            for _item in self.configured_attribute_statements:
                if _item:
                    _items.append(_item.to_dict())
            _dict["configuredAttributeStatements"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in inline_hooks (list)
        _items = []
        if self.inline_hooks:
            for _item in self.inline_hooks:
                if _item:
                    _items.append(_item.to_dict())
            _dict["inlineHooks"] = _items
        # override the default output from pydantic by calling `to_dict()` of participate_slo
        if self.participate_slo:
            if not isinstance(self.participate_slo, dict):
                _dict["participateSlo"] = self.participate_slo.to_dict()
            else:
                _dict["participateSlo"] = self.participate_slo

        # override the default output from pydantic by calling `to_dict()` of slo
        if self.slo:
            if not isinstance(self.slo, dict):
                _dict["slo"] = self.slo.to_dict()
            else:
                _dict["slo"] = self.slo

        # override the default output from pydantic by calling `to_dict()` of sp_certificate
        if self.sp_certificate:
            if not isinstance(self.sp_certificate, dict):
                _dict["spCertificate"] = self.sp_certificate.to_dict()
            else:
                _dict["spCertificate"] = self.sp_certificate

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "acsEndpoints": (
                    [AcsEndpoint.from_dict(_item) for _item in obj["acsEndpoints"]]
                    if obj.get("acsEndpoints") is not None
                    else None
                ),
                "allowMultipleAcsEndpoints": obj.get("allowMultipleAcsEndpoints"),
                "assertionSigned": obj.get("assertionSigned"),
                "attributeStatements": (
                    [
                        SamlAttributeStatement.from_dict(_item)
                        for _item in obj["attributeStatements"]
                    ]
                    if obj.get("attributeStatements") is not None
                    else None
                ),
                "audience": obj.get("audience"),
                "audienceOverride": obj.get("audienceOverride"),
                "authnContextClassRef": obj.get("authnContextClassRef"),
                "configuredAttributeStatements": (
                    [
                        SamlAttributeStatement.from_dict(_item)
                        for _item in obj["configuredAttributeStatements"]
                    ]
                    if obj.get("configuredAttributeStatements") is not None
                    else None
                ),
                "defaultRelayState": obj.get("defaultRelayState"),
                "destination": obj.get("destination"),
                "destinationOverride": obj.get("destinationOverride"),
                "digestAlgorithm": obj.get("digestAlgorithm"),
                "honorForceAuthn": obj.get("honorForceAuthn"),
                "idpIssuer": obj.get("idpIssuer"),
                "inlineHooks": (
                    [SignOnInlineHook.from_dict(_item) for _item in obj["inlineHooks"]]
                    if obj.get("inlineHooks") is not None
                    else None
                ),
                "participateSlo": (
                    SloParticipate.from_dict(obj["participateSlo"])
                    if obj.get("participateSlo") is not None
                    else None
                ),
                "recipient": obj.get("recipient"),
                "recipientOverride": obj.get("recipientOverride"),
                "requestCompressed": obj.get("requestCompressed"),
                "responseSigned": obj.get("responseSigned"),
                "signatureAlgorithm": obj.get("signatureAlgorithm"),
                "slo": (
                    SingleLogout.from_dict(obj["slo"])
                    if obj.get("slo") is not None
                    else None
                ),
                "spCertificate": (
                    SpCertificate.from_dict(obj["spCertificate"])
                    if obj.get("spCertificate") is not None
                    else None
                ),
                "spIssuer": obj.get("spIssuer"),
                "ssoAcsUrl": obj.get("ssoAcsUrl"),
                "ssoAcsUrlOverride": obj.get("ssoAcsUrlOverride"),
                "subjectNameIdFormat": obj.get("subjectNameIdFormat"),
                "subjectNameIdTemplate": obj.get("subjectNameIdTemplate"),
            }
        )
        return _obj
