# coding: utf-8

"""
    allure-testops-service

    Branch **HEAD**  Commit **623f6ed302ba4b651cf9040faca4635af2d93b7c**

    The version of the OpenAPI document: 25.4.1
    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 importlib import import_module
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from src.client.generated.models.ext_form_field_checkbox import ExtFormFieldCheckbox
    from src.client.generated.models.ext_form_field_composite import ExtFormFieldComposite
    from src.client.generated.models.ext_form_field_external_select import ExtFormFieldExternalSelect
    from src.client.generated.models.ext_form_field_form_choice import ExtFormFieldFormChoice
    from src.client.generated.models.ext_form_field_list import ExtFormFieldList
    from src.client.generated.models.ext_form_field_number import ExtFormFieldNumber
    from src.client.generated.models.ext_form_field_password import ExtFormFieldPassword
    from src.client.generated.models.ext_form_field_select import ExtFormFieldSelect
    from src.client.generated.models.ext_form_field_slider import ExtFormFieldSlider
    from src.client.generated.models.ext_form_field_text import ExtFormFieldText
    from src.client.generated.models.ext_form_field_textarea import ExtFormFieldTextarea
    from src.client.generated.models.ext_form_field_unknown import ExtFormFieldUnknown

class ExtFormField(BaseModel):
    """
    ExtFormField
    """ # noqa: E501
    depends_on_fields: Optional[List[StrictStr]] = Field(default=None, alias="dependsOnFields")
    deprecated: Optional[StrictBool] = None
    name: Optional[StrictStr] = None
    required: Optional[StrictBool] = None
    type: StrictStr
    __properties: ClassVar[List[str]] = ["dependsOnFields", "deprecated", "name", "required", "type"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = 'type'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'ExtFormFieldCheckbox': 'ExtFormFieldCheckbox','ExtFormFieldComposite': 'ExtFormFieldComposite','ExtFormFieldExternalSelect': 'ExtFormFieldExternalSelect','ExtFormFieldFormChoice': 'ExtFormFieldFormChoice','ExtFormFieldList': 'ExtFormFieldList','ExtFormFieldNumber': 'ExtFormFieldNumber','ExtFormFieldPassword': 'ExtFormFieldPassword','ExtFormFieldSelect': 'ExtFormFieldSelect','ExtFormFieldSlider': 'ExtFormFieldSlider','ExtFormFieldText': 'ExtFormFieldText','ExtFormFieldTextarea': 'ExtFormFieldTextarea','ExtFormFieldUnknown': 'ExtFormFieldUnknown'
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj[cls.__discriminator_property_name]
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    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[Union[ExtFormFieldCheckbox, ExtFormFieldComposite, ExtFormFieldExternalSelect, ExtFormFieldFormChoice, ExtFormFieldList, ExtFormFieldNumber, ExtFormFieldPassword, ExtFormFieldSelect, ExtFormFieldSlider, ExtFormFieldText, ExtFormFieldTextarea, ExtFormFieldUnknown]]:
        """Create an instance of ExtFormField 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,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[ExtFormFieldCheckbox, ExtFormFieldComposite, ExtFormFieldExternalSelect, ExtFormFieldFormChoice, ExtFormFieldList, ExtFormFieldNumber, ExtFormFieldPassword, ExtFormFieldSelect, ExtFormFieldSlider, ExtFormFieldText, ExtFormFieldTextarea, ExtFormFieldUnknown]]:
        """Create an instance of ExtFormField from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'ExtFormFieldCheckbox':
            return import_module("src.client.generated.models.ext_form_field_checkbox").ExtFormFieldCheckbox.from_dict(obj)
        if object_type ==  'ExtFormFieldComposite':
            return import_module("src.client.generated.models.ext_form_field_composite").ExtFormFieldComposite.from_dict(obj)
        if object_type ==  'ExtFormFieldExternalSelect':
            return import_module("src.client.generated.models.ext_form_field_external_select").ExtFormFieldExternalSelect.from_dict(obj)
        if object_type ==  'ExtFormFieldFormChoice':
            return import_module("src.client.generated.models.ext_form_field_form_choice").ExtFormFieldFormChoice.from_dict(obj)
        if object_type ==  'ExtFormFieldList':
            return import_module("src.client.generated.models.ext_form_field_list").ExtFormFieldList.from_dict(obj)
        if object_type ==  'ExtFormFieldNumber':
            return import_module("src.client.generated.models.ext_form_field_number").ExtFormFieldNumber.from_dict(obj)
        if object_type ==  'ExtFormFieldPassword':
            return import_module("src.client.generated.models.ext_form_field_password").ExtFormFieldPassword.from_dict(obj)
        if object_type ==  'ExtFormFieldSelect':
            return import_module("src.client.generated.models.ext_form_field_select").ExtFormFieldSelect.from_dict(obj)
        if object_type ==  'ExtFormFieldSlider':
            return import_module("src.client.generated.models.ext_form_field_slider").ExtFormFieldSlider.from_dict(obj)
        if object_type ==  'ExtFormFieldText':
            return import_module("src.client.generated.models.ext_form_field_text").ExtFormFieldText.from_dict(obj)
        if object_type ==  'ExtFormFieldTextarea':
            return import_module("src.client.generated.models.ext_form_field_textarea").ExtFormFieldTextarea.from_dict(obj)
        if object_type ==  'ExtFormFieldUnknown':
            return import_module("src.client.generated.models.ext_form_field_unknown").ExtFormFieldUnknown.from_dict(obj)

        raise ValueError("ExtFormField failed to lookup discriminator value from " +
                            json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
                            ", mapping: " + json.dumps(cls.__discriminator_value_class_map))


