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

from okta.models.auth_settings import AuthSettings
from okta.models.provisioning_details import ProvisioningDetails
from okta.models.sso import Sso
from okta.models.submission_action import SubmissionAction
from okta.models.submission_capability import SubmissionCapability
from okta.models.submission_response_app_contact_details_inner import (
    SubmissionResponseAppContactDetailsInner,
)
from okta.models.submission_response_config_inner import SubmissionResponseConfigInner
from okta.models.submission_response_global_token_revocation import (
    SubmissionResponseGlobalTokenRevocation,
)


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

    actions: Optional[List[SubmissionAction]] = Field(
        default=None, description="List of actions supported by this integration"
    )
    app_contact_details: Optional[List[SubmissionResponseAppContactDetailsInner]] = (
        Field(
            default=None,
            description="List of contact details for the app integration",
            alias="appContactDetails",
        )
    )
    var_auth_settings: Optional[AuthSettings] = Field(
        default=None, alias="authSettings"
    )
    capabilities: Optional[List[SubmissionCapability]] = Field(
        default=None, description="List of capabilities supported by this integration"
    )
    config: Optional[List[SubmissionResponseConfigInner]] = Field(
        default=None,
        description="List of org-level variables for the customer per-tenant configuration. For example, a `subdomain` "
        "variable can be used in the ACS URL: `https://${org.subdomain}.example.com/saml/login`",
    )
    description: Optional[
        Annotated[str, Field(min_length=1, strict=True, max_length=1024)]
    ] = Field(
        default=None,
        description="A general description of your application and the benefits provided to your customers",
    )
    global_token_revocation: Optional[SubmissionResponseGlobalTokenRevocation] = Field(
        default=None, alias="globalTokenRevocation"
    )
    id: Optional[StrictStr] = Field(default=None, description="OIN Integration ID")
    last_published: Optional[StrictStr] = Field(
        default=None,
        description="Timestamp when the OIN Integration was last published",
        alias="lastPublished",
    )
    last_updated: Optional[StrictStr] = Field(
        default=None,
        description="Timestamp when the OIN Integration instance was last updated",
        alias="lastUpdated",
    )
    last_updated_by: Optional[StrictStr] = Field(
        default=None,
        description="ID of the user who made the last update",
        alias="lastUpdatedBy",
    )
    logo: Optional[StrictStr] = Field(
        default=None,
        description="URL to an uploaded application logo. This logo appears next to your app integration name in the OIN "
        "catalog. You must first [Upload an OIN Integration logo]("
        "/openapi/okta-management/management/tag/YourOinIntegrations/#tag/YourOinIntegrations/operation"
        "/uploadSubmissionLogo) to obtain the logo URL before you can specify this value.",
    )
    name: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=64)]] = (
        Field(
            default=None,
            description="The app integration name. This is the main title used for your integration in the OIN catalog.",
        )
    )
    provisioning: Optional[ProvisioningDetails] = None
    sso: Optional[Sso] = None
    status: Optional[StrictStr] = Field(
        default=None, description="Status of the OIN Integration submission"
    )
    __properties: ClassVar[List[str]] = [
        "actions",
        "appContactDetails",
        "authSettings",
        "capabilities",
        "config",
        "description",
        "globalTokenRevocation",
        "id",
        "lastPublished",
        "lastUpdated",
        "lastUpdatedBy",
        "logo",
        "name",
        "provisioning",
        "sso",
        "status",
    ]

    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 SubmissionResponse 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set(
            [
                "id",
                "last_published",
                "last_updated",
                "last_updated_by",
                "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 each item in actions (list)
        _items = []
        if self.actions:
            for _item in self.actions:
                if _item:
                    _items.append(_item.to_dict())
            _dict["actions"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in app_contact_details (list)
        _items = []
        if self.app_contact_details:
            for _item in self.app_contact_details:
                if _item:
                    _items.append(_item.to_dict())
            _dict["appContactDetails"] = _items
        # override the default output from pydantic by calling `to_dict()` of var_auth_settings
        if self.var_auth_settings:
            if not isinstance(self.var_auth_settings, dict):
                _dict["authSettings"] = self.var_auth_settings.to_dict()
            else:
                _dict["authSettings"] = self.var_auth_settings

        # override the default output from pydantic by calling `to_dict()` of each item in capabilities (list)
        _items = []
        if self.capabilities:
            for _item in self.capabilities:
                if _item:
                    _items.append(_item.to_dict())
            _dict["capabilities"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in config (list)
        _items = []
        if self.config:
            for _item in self.config:
                if _item:
                    _items.append(_item.to_dict())
            _dict["config"] = _items
        # override the default output from pydantic by calling `to_dict()` of global_token_revocation
        if self.global_token_revocation:
            if not isinstance(self.global_token_revocation, dict):
                _dict["globalTokenRevocation"] = self.global_token_revocation.to_dict()
            else:
                _dict["globalTokenRevocation"] = self.global_token_revocation

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "actions": (
                    [SubmissionAction.from_dict(_item) for _item in obj["actions"]]
                    if obj.get("actions") is not None
                    else None
                ),
                "appContactDetails": (
                    [
                        SubmissionResponseAppContactDetailsInner.from_dict(_item)
                        for _item in obj["appContactDetails"]
                    ]
                    if obj.get("appContactDetails") is not None
                    else None
                ),
                "authSettings": (
                    AuthSettings.from_dict(obj["authSettings"])
                    if obj.get("authSettings") is not None
                    else None
                ),
                "capabilities": (
                    [
                        SubmissionCapability.from_dict(_item)
                        for _item in obj["capabilities"]
                    ]
                    if obj.get("capabilities") is not None
                    else None
                ),
                "config": (
                    [
                        SubmissionResponseConfigInner.from_dict(_item)
                        for _item in obj["config"]
                    ]
                    if obj.get("config") is not None
                    else None
                ),
                "description": obj.get("description"),
                "globalTokenRevocation": (
                    SubmissionResponseGlobalTokenRevocation.from_dict(
                        obj["globalTokenRevocation"]
                    )
                    if obj.get("globalTokenRevocation") is not None
                    else None
                ),
                "id": obj.get("id"),
                "lastPublished": obj.get("lastPublished"),
                "lastUpdated": obj.get("lastUpdated"),
                "lastUpdatedBy": obj.get("lastUpdatedBy"),
                "logo": obj.get("logo"),
                "name": obj.get("name"),
                "provisioning": (
                    ProvisioningDetails.from_dict(obj["provisioning"])
                    if obj.get("provisioning") is not None
                    else None
                ),
                "sso": (
                    Sso.from_dict(obj["sso"]) if obj.get("sso") is not None else None
                ),
                "status": obj.get("status"),
            }
        )
        return _obj
