# 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 typing_extensions import Annotated
from boldsign.models.attachment_info import AttachmentInfo
from boldsign.models.conditional_rule import ConditionalRule
from boldsign.models.editable_date_field_settings import EditableDateFieldSettings
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 FormField(BaseModel):
    """
    FormField
    """ # noqa: E501
    field_type: StrictStr = Field(alias="fieldType")
    page_number: StrictInt = Field(alias="pageNumber")
    bounds: Rectangle
    id: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    is_required: Optional[StrictBool] = Field(default=None, alias="isRequired")
    is_read_only: Optional[StrictBool] = Field(default=None, alias="isReadOnly")
    value: Optional[StrictStr] = None
    font_size: Optional[Union[Annotated[float, Field(strict=True, ge=0)], Annotated[int, Field(strict=True, ge=0)]]] = Field(default=None, alias="fontSize")
    font: Optional[StrictStr] = None
    font_hex_color: Optional[StrictStr] = Field(default=None, alias="fontHexColor")
    is_bold_font: Optional[StrictBool] = Field(default=None, alias="isBoldFont")
    is_italic_font: Optional[StrictBool] = Field(default=None, alias="isItalicFont")
    is_under_line_font: Optional[StrictBool] = Field(default=None, alias="isUnderLineFont")
    line_height: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=0)]] = Field(default=None, alias="lineHeight")
    character_limit: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=0)]] = Field(default=None, alias="characterLimit")
    group_name: Optional[StrictStr] = Field(default=None, alias="groupName")
    label: Optional[StrictStr] = None
    place_holder: Optional[StrictStr] = Field(default=None, alias="placeHolder")
    validation_type: Optional[StrictStr] = Field(default=None, alias="validationType")
    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")
    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")
    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[Annotated[int, Field(le=2147483647, strict=True, ge=-1)]] = Field(default=None, alias="tabIndex")
    __properties: ClassVar[List[str]] = ["fieldType", "pageNumber", "bounds", "id", "name", "isRequired", "isReadOnly", "value", "fontSize", "font", "fontHexColor", "isBoldFont", "isItalicFont", "isUnderLineFont", "lineHeight", "characterLimit", "groupName", "label", "placeHolder", "validationType", "validationCustomRegex", "validationCustomRegexMessage", "dateFormat", "timeFormat", "imageInfo", "attachmentInfo", "editableDateFieldSettings", "hyperlinkText", "conditionalRules", "dataSyncTag", "dropdownOptions", "textAlign", "textDirection", "characterSpacing", "backgroundHexColor", "tabIndex"]

    @field_validator('field_type')
    def field_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['Signature', 'Initial', 'CheckBox', 'TextBox', 'Label', 'DateSigned', 'RadioButton', 'Image', 'Attachment', 'EditableDate', 'Hyperlink', 'Dropdown', 'Title', 'Company']):
            raise ValueError("must be one of enum values ('Signature', 'Initial', 'CheckBox', 'TextBox', 'Label', 'DateSigned', 'RadioButton', 'Image', 'Attachment', 'EditableDate', 'Hyperlink', 'Dropdown', 'Title', 'Company')")
        return value

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

        if value not in set(['Helvetica', 'Courier', 'TimesRoman', 'NotoSans']):
            raise ValueError("must be one of enum values ('Helvetica', 'Courier', 'TimesRoman', 'NotoSans')")
        return value

    @field_validator('validation_type')
    def validation_type_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

    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))
                    else:
                        data.append((key, json.dumps(value[index], ensure_ascii=False)))
            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 FormField 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 FormField from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "fieldType": obj.get("fieldType"),
            "pageNumber": obj.get("pageNumber"),
            "bounds": Rectangle.from_dict(obj["bounds"]) if obj.get("bounds") is not None else None,
            "id": obj.get("id"),
            "name": obj.get("name"),
            "isRequired": obj.get("isRequired"),
            "isReadOnly": obj.get("isReadOnly"),
            "value": obj.get("value"),
            "fontSize": obj.get("fontSize"),
            "font": obj.get("font"),
            "fontHexColor": obj.get("fontHexColor"),
            "isBoldFont": obj.get("isBoldFont"),
            "isItalicFont": obj.get("isItalicFont"),
            "isUnderLineFont": obj.get("isUnderLineFont"),
            "lineHeight": obj.get("lineHeight"),
            "characterLimit": obj.get("characterLimit"),
            "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,
            "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,
            "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")
        })
        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 {
            "field_type": "(str,)",
            "page_number": "(int,)",
            "bounds": "(Rectangle,)",
            "id": "(str,)",
            "name": "(str,)",
            "is_required": "(bool,)",
            "is_read_only": "(bool,)",
            "value": "(str,)",
            "font_size": "(float,)",
            "font": "(str,)",
            "font_hex_color": "(str,)",
            "is_bold_font": "(bool,)",
            "is_italic_font": "(bool,)",
            "is_under_line_font": "(bool,)",
            "line_height": "(int,)",
            "character_limit": "(int,)",
            "group_name": "(str,)",
            "label": "(str,)",
            "place_holder": "(str,)",
            "validation_type": "(str,)",
            "validation_custom_regex": "(str,)",
            "validation_custom_regex_message": "(str,)",
            "date_format": "(str,)",
            "time_format": "(str,)",
            "image_info": "(ImageInfo,)",
            "attachment_info": "(AttachmentInfo,)",
            "editable_date_field_settings": "(EditableDateFieldSettings,)",
            "hyperlink_text": "(str,)",
            "conditional_rules": "(List[ConditionalRule],)",
            "data_sync_tag": "(str,)",
            "dropdown_options": "(List[str],)",
            "text_align": "(str,)",
            "text_direction": "(str,)",
            "character_spacing": "(float,)",
            "background_hex_color": "(str,)",
            "tab_index": "(int,)",
        }

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

