# 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.application_settings_notes import ApplicationSettingsNotes
from okta.models.application_settings_notifications import (
    ApplicationSettingsNotifications,
)
from okta.models.office365_application_settings_application import (
    Office365ApplicationSettingsApplication,
)
from okta.models.oin_saml11_application_settings_sign_on import (
    OINSaml11ApplicationSettingsSignOn,
)


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

    em_opt_in_status: Optional[StrictStr] = Field(
        default=None,
        description="The entitlement management opt-in status for the app",
        alias="emOptInStatus",
    )
    identity_store_id: Optional[StrictStr] = Field(
        default=None,
        description="Identifies an additional identity store app, if your app supports it. The `identityStoreId` value must "
        "be a valid identity store app ID. This identity store app must be created in the same org as your app.",
        alias="identityStoreId",
    )
    implicit_assignment: Optional[StrictBool] = Field(
        default=None,
        description="Controls whether Okta automatically assigns users to the app based on the user's role or group "
        "membership.",
        alias="implicitAssignment",
    )
    inline_hook_id: Optional[StrictStr] = Field(
        default=None,
        description="Identifier of an inline hook. Inline hooks are outbound calls from Okta to your own custom code, "
        "triggered at specific points in Okta process flows. They allow you to integrate custom functionality "
        "into those flows. See [Inline hooks](/openapi/okta-management/management/tag/InlineHook/).",
        alias="inlineHookId",
    )
    notes: Optional[ApplicationSettingsNotes] = None
    notifications: Optional[ApplicationSettingsNotifications] = None
    app: Office365ApplicationSettingsApplication
    sign_on: Optional[OINSaml11ApplicationSettingsSignOn] = Field(
        default=None, alias="signOn"
    )
    __properties: ClassVar[List[str]] = [
        "emOptInStatus",
        "identityStoreId",
        "implicitAssignment",
        "inlineHookId",
        "notes",
        "notifications",
        "app",
        "signOn",
    ]

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

        if value not in set(["DISABLED", "DISABLING", "ENABLED", "ENABLING", "NONE"]):
            raise ValueError(
                "must be one of enum values ('DISABLED', 'DISABLING', 'ENABLED', 'ENABLING', '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 Office365ApplicationSettings 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.
        """
        excluded_fields: Set[str] = set(
            [
                "em_opt_in_status",
            ]
        )

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "emOptInStatus": obj.get("emOptInStatus"),
                "identityStoreId": obj.get("identityStoreId"),
                "implicitAssignment": obj.get("implicitAssignment"),
                "inlineHookId": obj.get("inlineHookId"),
                "notes": (
                    ApplicationSettingsNotes.from_dict(obj["notes"])
                    if obj.get("notes") is not None
                    else None
                ),
                "notifications": (
                    ApplicationSettingsNotifications.from_dict(obj["notifications"])
                    if obj.get("notifications") is not None
                    else None
                ),
                "app": (
                    Office365ApplicationSettingsApplication.from_dict(obj["app"])
                    if obj.get("app") is not None
                    else None
                ),
                "signOn": (
                    OINSaml11ApplicationSettingsSignOn.from_dict(obj["signOn"])
                    if obj.get("signOn") is not None
                    else None
                ),
            }
        )
        return _obj
