# coding: utf-8

"""
    BoldSign API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1
    Contact: support@boldsign.com
    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, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from boldsign.models.attachment_info import AttachmentInfo
from boldsign.models.collaboration_settings import CollaborationSettings
from boldsign.models.conditional_rule import ConditionalRule
from boldsign.models.editable_date_field_settings import EditableDateFieldSettings
from boldsign.models.file_info import FileInfo
from boldsign.models.formula_field_settings import FormulaFieldSettings
from boldsign.models.image_info import ImageInfo
from boldsign.models.rectangle import Rectangle
from typing import Optional, Set, Tuple
from typing_extensions import Self
import io
from pydantic import StrictBool
from typing import Union

class DocumentFormFields(BaseModel):
    """
    DocumentFormFields
    """ # noqa: E501
    id: Optional[StrictStr] = None
    form_field_id: Optional[StrictStr] = Field(default=None, alias="formFieldId")
    type: Optional[StrictStr] = None
    value: Optional[StrictStr] = None
    font: Optional[StrictStr] = None
    is_required: Optional[StrictBool] = Field(default=None, alias="isRequired")
    is_read_only: Optional[StrictBool] = Field(default=None, alias="isReadOnly")
    line_height: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="lineHeight")
    font_size: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="fontSize")
    font_color: Optional[StrictStr] = Field(default=None, alias="fontColor")
    is_underline: Optional[StrictBool] = Field(default=None, alias="isUnderline")
    is_italic: Optional[StrictBool] = Field(default=None, alias="isItalic")
    is_bold: Optional[StrictBool] = Field(default=None, alias="isBold")
    group_name: Optional[StrictStr] = Field(default=None, alias="groupName")
    label: Optional[StrictStr] = None
    placeholder: Optional[StrictStr] = None
    validationtype: Optional[StrictStr] = None
    validation_custom_regex: Optional[StrictStr] = Field(default=None, alias="validationCustomRegex")
    validation_custom_regex_message: Optional[StrictStr] = Field(default=None, alias="validationCustomRegexMessage")
    date_format: Optional[StrictStr] = Field(default=None, alias="dateFormat")
    time_format: Optional[StrictStr] = Field(default=None, alias="timeFormat")
    image_info: Optional[ImageInfo] = Field(default=None, alias="imageInfo")
    attachment_info: Optional[AttachmentInfo] = Field(default=None, alias="attachmentInfo")
    file_info: Optional[FileInfo] = Field(default=None, alias="fileInfo")
    editable_date_field_settings: Optional[EditableDateFieldSettings] = Field(default=None, alias="editableDateFieldSettings")
    hyperlink_text: Optional[StrictStr] = Field(default=None, alias="hyperlinkText")
    conditional_rules: Optional[List[ConditionalRule]] = Field(default=None, alias="conditionalRules")
    bounds: Optional[Rectangle] = None
    page_number: Optional[StrictInt] = Field(default=None, alias="pageNumber")
    data_sync_tag: Optional[StrictStr] = Field(default=None, alias="dataSyncTag")
    dropdown_options: Optional[List[StrictStr]] = Field(default=None, alias="dropdownOptions")
    text_align: Optional[StrictStr] = Field(default=None, alias="textAlign")
    text_direction: Optional[StrictStr] = Field(default=None, alias="textDirection")
    character_spacing: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="characterSpacing")
    background_hex_color: Optional[StrictStr] = Field(default=None, alias="backgroundHexColor")
    tab_index: Optional[StrictInt] = Field(default=None, alias="tabIndex")
    formula_field_settings: Optional[FormulaFieldSettings] = Field(default=None, alias="formulaFieldSettings")
    resize_option: Optional[StrictStr] = Field(default=None, alias="resizeOption")
    allow_edit_form_field: Optional[StrictBool] = Field(default=None, alias="allowEditFormField")
    allow_delete_form_field: Optional[StrictBool] = Field(default=None, alias="allowDeleteFormField")
    collaboration_settings: Optional[CollaborationSettings] = Field(default=None, alias="collaborationSettings")
    hidden: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = ["id", "formFieldId", "type", "value", "font", "isRequired", "isReadOnly", "lineHeight", "fontSize", "fontColor", "isUnderline", "isItalic", "isBold", "groupName", "label", "placeholder", "validationtype", "validationCustomRegex", "validationCustomRegexMessage", "dateFormat", "timeFormat", "imageInfo", "attachmentInfo", "fileInfo", "editableDateFieldSettings", "hyperlinkText", "conditionalRules", "bounds", "pageNumber", "dataSyncTag", "dropdownOptions", "textAlign", "textDirection", "characterSpacing", "backgroundHexColor", "tabIndex", "formulaFieldSettings", "resizeOption", "allowEditFormField", "allowDeleteFormField", "collaborationSettings", "hidden"]

    @field_validator('validationtype')
    def validationtype_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['None', 'NumbersOnly', 'EmailAddress', 'Currency', 'CustomRegex']):
            raise ValueError("must be one of enum values ('None', 'NumbersOnly', 'EmailAddress', 'Currency', 'CustomRegex')")
        return value

    @field_validator('text_align')
    def text_align_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

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

    @field_validator('text_direction')
    def text_direction_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

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

    @field_validator('resize_option')
    def resize_option_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['GrowVertically', 'GrowHorizontally', 'GrowBoth', 'Fixed', 'AutoResizeFont']):
            raise ValueError("must be one of enum values ('GrowVertically', 'GrowHorizontally', 'GrowBoth', 'Fixed', 'AutoResizeFont')")
        return value

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


    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())

    def to_json_form_params(self, excluded_fields: Set[str] = None) -> List[Tuple[str, str]]:
        data: List[Tuple[str, str]] = []

        for key, value in self.to_dict(excluded_fields).items():
            if isinstance(value, (int, str, bool)):
                data.append((key, value))
            elif isinstance(value, list):
                for index, item in enumerate(value):
                    if(isinstance(item, (int, str, bool))):
                        data.append((f'{key}[{index}]', item))
                    elif key == 'files' and isinstance(item, dict):
                        for attribute_name, attribute_value in item.items():
                            full_key = f'{key}[{index}].{attribute_name}'
                            if excluded_fields and full_key in excluded_fields:
                                continue
                            data.append((full_key, attribute_value))
                    else:
                        data.append((key, json.dumps(value[index], ensure_ascii=False)))
            elif isinstance(value, dict):
                for dict_key, dict_value in value.items():
                    if dict_value is not None:
                        data.append((f'{key}[{dict_key}]', str(dict_value)))
            else:
                data.append((key, json.dumps(value, ensure_ascii=False)))

        return data

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of DocumentFormFields from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self, excluded_fields: Set[str] = None) -> 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.
        """

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "formFieldId": obj.get("formFieldId"),
            "type": obj.get("type"),
            "value": obj.get("value"),
            "font": obj.get("font"),
            "isRequired": obj.get("isRequired"),
            "isReadOnly": obj.get("isReadOnly"),
            "lineHeight": obj.get("lineHeight"),
            "fontSize": obj.get("fontSize"),
            "fontColor": obj.get("fontColor"),
            "isUnderline": obj.get("isUnderline"),
            "isItalic": obj.get("isItalic"),
            "isBold": obj.get("isBold"),
            "groupName": obj.get("groupName"),
            "label": obj.get("label"),
            "placeholder": obj.get("placeholder"),
            "validationtype": obj.get("validationtype"),
            "validationCustomRegex": obj.get("validationCustomRegex"),
            "validationCustomRegexMessage": obj.get("validationCustomRegexMessage"),
            "dateFormat": obj.get("dateFormat"),
            "timeFormat": obj.get("timeFormat"),
            "imageInfo": ImageInfo.from_dict(obj["imageInfo"]) if obj.get("imageInfo") is not None else None,
            "attachmentInfo": AttachmentInfo.from_dict(obj["attachmentInfo"]) if obj.get("attachmentInfo") is not None else None,
            "fileInfo": FileInfo.from_dict(obj["fileInfo"]) if obj.get("fileInfo") is not None else None,
            "editableDateFieldSettings": EditableDateFieldSettings.from_dict(obj["editableDateFieldSettings"]) if obj.get("editableDateFieldSettings") is not None else None,
            "hyperlinkText": obj.get("hyperlinkText"),
            "conditionalRules": [ConditionalRule.from_dict(_item) for _item in obj["conditionalRules"]] if obj.get("conditionalRules") is not None else None,
            "bounds": Rectangle.from_dict(obj["bounds"]) if obj.get("bounds") is not None else None,
            "pageNumber": obj.get("pageNumber"),
            "dataSyncTag": obj.get("dataSyncTag"),
            "dropdownOptions": obj.get("dropdownOptions"),
            "textAlign": obj.get("textAlign"),
            "textDirection": obj.get("textDirection"),
            "characterSpacing": obj.get("characterSpacing"),
            "backgroundHexColor": obj.get("backgroundHexColor"),
            "tabIndex": obj.get("tabIndex"),
            "formulaFieldSettings": FormulaFieldSettings.from_dict(obj["formulaFieldSettings"]) if obj.get("formulaFieldSettings") is not None else None,
            "resizeOption": obj.get("resizeOption"),
            "allowEditFormField": obj.get("allowEditFormField"),
            "allowDeleteFormField": obj.get("allowDeleteFormField"),
            "collaborationSettings": CollaborationSettings.from_dict(obj["collaborationSettings"]) if obj.get("collaborationSettings") is not None else None,
            "hidden": obj.get("hidden")
        })
        return _obj

    @classmethod
    def init(cls, data: Any) -> Self:
        """
        Attempt to instantiate and hydrate a new instance of this class
        """
        if isinstance(data, str):
            data = json.loads(data)

        return cls.from_dict(data)

    @classmethod
    def openapi_types(cls) -> Dict[str, str]:
        return {
            "id": "(str,)",
            "form_field_id": "(str,)",
            "type": "(str,)",
            "value": "(str,)",
            "font": "(str,)",
            "is_required": "(bool,)",
            "is_read_only": "(bool,)",
            "line_height": "(float,)",
            "font_size": "(float,)",
            "font_color": "(str,)",
            "is_underline": "(bool,)",
            "is_italic": "(bool,)",
            "is_bold": "(bool,)",
            "group_name": "(str,)",
            "label": "(str,)",
            "placeholder": "(str,)",
            "validationtype": "(str,)",
            "validation_custom_regex": "(str,)",
            "validation_custom_regex_message": "(str,)",
            "date_format": "(str,)",
            "time_format": "(str,)",
            "image_info": "(ImageInfo,)",
            "attachment_info": "(AttachmentInfo,)",
            "file_info": "(FileInfo,)",
            "editable_date_field_settings": "(EditableDateFieldSettings,)",
            "hyperlink_text": "(str,)",
            "conditional_rules": "(List[ConditionalRule],)",
            "bounds": "(Rectangle,)",
            "page_number": "(int,)",
            "data_sync_tag": "(str,)",
            "dropdown_options": "(List[str],)",
            "text_align": "(str,)",
            "text_direction": "(str,)",
            "character_spacing": "(float,)",
            "background_hex_color": "(str,)",
            "tab_index": "(int,)",
            "formula_field_settings": "(FormulaFieldSettings,)",
            "resize_option": "(str,)",
            "allow_edit_form_field": "(bool,)",
            "allow_delete_form_field": "(bool,)",
            "collaboration_settings": "(CollaborationSettings,)",
            "hidden": "(bool,)",
        }

    @classmethod
    def openapi_type_is_array(cls, property_name: str) -> bool:
        return property_name in [
            "conditional_rules",
            "dropdown_options",
        ]

