# coding: utf-8

"""
    Logto API references

    API references for Logto services.

    The version of the OpenAPI document: Cloud
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from py_logto.models.list_connectors200_response_inner_form_items_inner_one_of_show_conditions_inner import ListConnectors200ResponseInnerFormItemsInnerOneOfShowConditionsInner
from typing import Optional, Set
from typing_extensions import Self

class ListConnectors200ResponseInnerFormItemsInnerOneOf2(BaseModel):
    """
    ListConnectors200ResponseInnerFormItemsInnerOneOf2
    """ # noqa: E501
    type: StrictStr
    key: StrictStr
    label: StrictStr
    placeholder: Optional[StrictStr] = None
    required: Optional[StrictBool] = None
    default_value: Optional[Any] = Field(default=None, alias="defaultValue")
    show_conditions: Optional[List[ListConnectors200ResponseInnerFormItemsInnerOneOfShowConditionsInner]] = Field(default=None, alias="showConditions")
    description: Optional[StrictStr] = None
    tooltip: Optional[StrictStr] = None
    is_confidential: Optional[StrictBool] = Field(default=None, alias="isConfidential")
    __properties: ClassVar[List[str]] = ["type", "key", "label", "placeholder", "required", "defaultValue", "showConditions", "description", "tooltip", "isConfidential"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['Text', 'Number', 'MultilineText', 'Switch', 'Json']):
            raise ValueError("must be one of enum values ('Text', 'Number', 'MultilineText', 'Switch', 'Json')")
        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 ListConnectors200ResponseInnerFormItemsInnerOneOf2 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 show_conditions (list)
        _items = []
        if self.show_conditions:
            for _item in self.show_conditions:
                if _item:
                    _items.append(_item.to_dict())
            _dict['showConditions'] = _items
        # set to None if default_value (nullable) is None
        # and model_fields_set contains the field
        if self.default_value is None and "default_value" in self.model_fields_set:
            _dict['defaultValue'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "key": obj.get("key"),
            "label": obj.get("label"),
            "placeholder": obj.get("placeholder"),
            "required": obj.get("required"),
            "defaultValue": obj.get("defaultValue"),
            "showConditions": [ListConnectors200ResponseInnerFormItemsInnerOneOfShowConditionsInner.from_dict(_item) for _item in obj["showConditions"]] if obj.get("showConditions") is not None else None,
            "description": obj.get("description"),
            "tooltip": obj.get("tooltip"),
            "isConfidential": obj.get("isConfidential")
        })
        return _obj


