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

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing_extensions import Annotated
from typing_extensions import Self

from okta.models.org_creation_admin import OrgCreationAdmin


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

    admin: OrgCreationAdmin
    created: Optional[datetime] = Field(
        default=None, description="Timestamp when the org was created"
    )
    edition: StrictStr = Field(
        description="Edition for the org. `SKU` is the only supported value."
    )
    id: Optional[StrictStr] = Field(default=None, description="Org ID")
    last_updated: Optional[datetime] = Field(
        default=None,
        description="Timestamp when the org was last updated",
        alias="lastUpdated",
    )
    name: Annotated[str, Field(strict=True)] = Field(
        description="Unique name of the org. This name appears in the HTML `<title>` tag of the new org sign-in page. Only "
        "less than 4-width UTF-8 encoded characters are allowed."
    )
    settings: Optional[Dict[str, Any]] = Field(
        default=None, description="Settings associated with the created org"
    )
    status: Optional[StrictStr] = Field(
        default=None,
        description="Status of the org. `ACTIVE` is returned after the org is created.",
    )
    subdomain: Annotated[str, Field(strict=True)] = Field(
        description="Subdomain of the org. Must be unique and include no spaces."
    )
    token: Optional[StrictStr] = Field(
        default=None,
        description="API token associated with the child org super admin account. Use this API token to provision resources "
        "(such as policies, apps, and groups) on the newly created child org. This token is revoked if the super "
        "admin account is deactivated. > **Note:** If this API token expires, sign in to the Admin Console as "
        "the super admin user and create a new API token. See [Create an API token]("
        "https://developer.okta.com/docs/guides/create-an-api-token/).",
    )
    token_type: Optional[StrictStr] = Field(
        default=None,
        description="Type of returned `token`. See [Okta API tokens]("
        "https://developer.okta.com/docs/guides/create-an-api-token/main/#okta-api-tokens).",
        alias="tokenType",
    )
    website: Optional[StrictStr] = Field(
        default=None, description="Default website for the org"
    )
    links: Optional[Dict[str, Any]] = Field(
        default=None,
        description="Specifies available link relations (see [Web Linking](https://www.rfc-editor.org/rfc/rfc8288)) using "
        "the [JSON Hypertext Application Language]("
        "https://datatracker.ietf.org/doc/html/draft-kelly-json-hal-06) specification",
        alias="_links",
    )
    __properties: ClassVar[List[str]] = [
        "admin",
        "created",
        "edition",
        "id",
        "lastUpdated",
        "name",
        "settings",
        "status",
        "subdomain",
        "token",
        "tokenType",
        "website",
        "_links",
    ]

    @field_validator("edition")
    def edition_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(["SKU"]):
            raise ValueError("must be one of enum values ('SKU')")
        return value

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

        if value not in set(["ACTIVE"]):
            raise ValueError("must be one of enum values ('ACTIVE')")
        return value

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

        if value not in set(["SSWS"]):
            raise ValueError("must be one of enum values ('SSWS')")
        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 ChildOrg 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set(
            [
                "created",
                "id",
                "last_updated",
                "settings",
                "status",
                "token",
                "token_type",
                "links",
            ]
        )

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "admin": (
                    OrgCreationAdmin.from_dict(obj["admin"])
                    if obj.get("admin") is not None
                    else None
                ),
                "created": obj.get("created"),
                "edition": obj.get("edition"),
                "id": obj.get("id"),
                "lastUpdated": obj.get("lastUpdated"),
                "name": obj.get("name"),
                "settings": obj.get("settings"),
                "status": obj.get("status"),
                "subdomain": obj.get("subdomain"),
                "token": obj.get("token"),
                "tokenType": obj.get("tokenType"),
                "website": obj.get("website"),
                "_links": obj.get("_links"),
            }
        )
        return _obj
