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

from okta.models.group_schema_attribute_enum_inner import GroupSchemaAttributeEnumInner
from okta.models.user_schema_attribute_enum import UserSchemaAttributeEnum
from okta.models.user_schema_attribute_format import UserSchemaAttributeFormat
from okta.models.user_schema_attribute_items import UserSchemaAttributeItems
from okta.models.user_schema_attribute_master import UserSchemaAttributeMaster
from okta.models.user_schema_attribute_mutability_string import (
    UserSchemaAttributeMutabilityString,
)
from okta.models.user_schema_attribute_permission import UserSchemaAttributePermission
from okta.models.user_schema_attribute_scope import UserSchemaAttributeScope
from okta.models.user_schema_attribute_type import UserSchemaAttributeType


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

    description: Optional[StrictStr] = Field(
        default=None, description="Description of the property"
    )
    enum: Optional[List[GroupSchemaAttributeEnumInner]] = Field(
        default=None,
        description="Enumerated value of the property.  The value of the property is limited to one of the values specified "
        "in the enum definition. The list of values for the enum must consist of unique elements.",
    )
    external_name: Optional[StrictStr] = Field(
        default=None,
        description="Name of the property as it exists in an external application",
        alias="externalName",
    )
    external_namespace: Optional[StrictStr] = Field(
        default=None,
        description="Namespace from the external application",
        alias="externalNamespace",
    )
    format: Optional[UserSchemaAttributeFormat] = Field(
        default=None,
        description="Identifies the type of data represented by the string",
    )
    items: Optional[UserSchemaAttributeItems] = None
    master: Optional[UserSchemaAttributeMaster] = Field(
        default=None, description="Identifies where the property is mastered"
    )
    max_length: Optional[StrictInt] = Field(
        default=None,
        description="Maximum character length of a string property",
        alias="maxLength",
    )
    min_length: Optional[StrictInt] = Field(
        default=None,
        description="Minimum character length of a string property",
        alias="minLength",
    )
    mutability: Optional[UserSchemaAttributeMutabilityString] = Field(
        default=None, description="Defines the mutability of the property"
    )
    one_of: Optional[List[UserSchemaAttributeEnum]] = Field(
        default=None,
        description="Non-empty array of valid JSON schemas.  The `oneOf` key is only supported in conjunction with `enum` "
        "and provides a mechanism to return a display name for the `enum` value.<br> Each schema has the "
        'following format:  ``` {   "const": "enumValue",   "title": "display name" } ```  When `enum` is used '
        "in conjunction with `oneOf`, you must keep the set of enumerated values and their order.<br> For "
        'example:  ``` "enum": ["S","M","L","XL"], "oneOf": [     {"const": "S", "title": "Small"},     '
        '{"const": "M", "title": "Medium"},     {"const": "L", "title": "Large"},     {"const": "XL", '
        '"title": "Extra Large"}   ] ```',
        alias="oneOf",
    )
    permissions: Optional[List[UserSchemaAttributePermission]] = Field(
        default=None, description="Access control permissions for the property"
    )
    required: Optional[StrictBool] = Field(
        default=None, description="Determines whether the property is required"
    )
    scope: Optional[UserSchemaAttributeScope] = Field(
        default=None,
        description="Determines whether a group attribute can be set at the individual or group level",
    )
    title: Optional[Annotated[str, Field(min_length=1, strict=True)]] = Field(
        default=None, description="User-defined display name for the property"
    )
    type: Optional[UserSchemaAttributeType] = Field(
        default=None, description="Type of property"
    )
    unique: Optional[StrictBool] = Field(
        default=None, description="Determines whether property values must be unique"
    )
    __properties: ClassVar[List[str]] = [
        "description",
        "enum",
        "externalName",
        "externalNamespace",
        "format",
        "items",
        "master",
        "maxLength",
        "minLength",
        "mutability",
        "oneOf",
        "permissions",
        "required",
        "scope",
        "title",
        "type",
        "unique",
    ]

    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 GroupSchemaAttribute 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 enum (list)
        _items = []
        if self.enum:
            for _item in self.enum:
                if _item:
                    _items.append(_item.to_dict())
            _dict["enum"] = _items
        # override the default output from pydantic by calling `to_dict()` of items
        if self.items:
            if not isinstance(self.items, dict):
                _dict["items"] = self.items.to_dict()
            else:
                _dict["items"] = self.items

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

        # override the default output from pydantic by calling `to_dict()` of each item in one_of (list)
        _items = []
        if self.one_of:
            for _item in self.one_of:
                if _item:
                    _items.append(_item.to_dict())
            _dict["oneOf"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in permissions (list)
        _items = []
        if self.permissions:
            for _item in self.permissions:
                if _item:
                    _items.append(_item.to_dict())
            _dict["permissions"] = _items
        # set to None if enum (nullable) is None
        # and model_fields_set contains the field
        if self.enum is None and "enum" in self.model_fields_set:
            _dict["enum"] = None

        # set to None if master (nullable) is None
        # and model_fields_set contains the field
        if self.master is None and "master" in self.model_fields_set:
            _dict["master"] = None

        # set to None if max_length (nullable) is None
        # and model_fields_set contains the field
        if self.max_length is None and "max_length" in self.model_fields_set:
            _dict["maxLength"] = None

        # set to None if min_length (nullable) is None
        # and model_fields_set contains the field
        if self.min_length is None and "min_length" in self.model_fields_set:
            _dict["minLength"] = None

        # set to None if one_of (nullable) is None
        # and model_fields_set contains the field
        if self.one_of is None and "one_of" in self.model_fields_set:
            _dict["oneOf"] = None

        # set to None if permissions (nullable) is None
        # and model_fields_set contains the field
        if self.permissions is None and "permissions" in self.model_fields_set:
            _dict["permissions"] = None

        # set to None if required (nullable) is None
        # and model_fields_set contains the field
        if self.required is None and "required" in self.model_fields_set:
            _dict["required"] = None

        # set to None if unique (nullable) is None
        # and model_fields_set contains the field
        if self.unique is None and "unique" in self.model_fields_set:
            _dict["unique"] = None

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "description": obj.get("description"),
                "enum": (
                    [
                        GroupSchemaAttributeEnumInner.from_dict(_item)
                        for _item in obj["enum"]
                    ]
                    if obj.get("enum") is not None
                    else None
                ),
                "externalName": obj.get("externalName"),
                "externalNamespace": obj.get("externalNamespace"),
                "format": obj.get("format"),
                "items": (
                    UserSchemaAttributeItems.from_dict(obj["items"])
                    if obj.get("items") is not None
                    else None
                ),
                "master": (
                    UserSchemaAttributeMaster.from_dict(obj["master"])
                    if obj.get("master") is not None
                    else None
                ),
                "maxLength": obj.get("maxLength"),
                "minLength": obj.get("minLength"),
                "mutability": obj.get("mutability"),
                "oneOf": (
                    [UserSchemaAttributeEnum.from_dict(_item) for _item in obj["oneOf"]]
                    if obj.get("oneOf") is not None
                    else None
                ),
                "permissions": (
                    [
                        UserSchemaAttributePermission.from_dict(_item)
                        for _item in obj["permissions"]
                    ]
                    if obj.get("permissions") is not None
                    else None
                ),
                "required": obj.get("required"),
                "scope": obj.get("scope"),
                "title": obj.get("title"),
                "type": obj.get("type"),
                "unique": obj.get("unique"),
            }
        )
        return _obj
