# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2, update_forward_refs
from ..core.serialization import FieldMetadata
from ..core.unchecked_base_model import UncheckedBaseModel
from .edit_bounding_box import EditBoundingBox
from .edit_json_schema_extend_edit_field_type import EditJsonSchemaExtendEditFieldType
from .edit_text_options import EditTextOptions


class EditJsonSchema(UncheckedBaseModel):
    """
    Schema definition for a field to edit in a PDF. This is a union type that supports:
    * `EditStringJSONSchema` - type: ["string", "null"], field_type: "text" | "signature"
    * `EditNumberJSONSchema` - type: ["number", "null"], field_type: "text"
    * `EditIntegerJSONSchema` - type: ["integer", "null"], field_type: "text"
    * `EditBooleanJSONSchema` - type: ["boolean", "null"], field_type: "checkbox" | "radio"
    * `EditArrayJSONSchema` - type: "array", field_type: "text" | "table"
    * `EditEnumJSONSchema` - has enum property (no type field), field_type: "radio" | "optionList" | "dropdown"
    * `EditObjectJSONSchema` - type: "object", field_type: "signature"

    All variants share common `extend_edit:*` properties for positioning and styling.
    """

    type: typing.Optional[typing.Any] = pydantic.Field(default=None)
    """
    The JSON schema type of the field. Can be:
    * A string: "array" or "object"
    * A nullable tuple array: ["string", "null"], ["number", "null"], ["integer", "null"], ["boolean", "null"]
    * Omitted for enum fields (use enum property instead)
    """

    description: typing.Optional[str] = pydantic.Field(default=None)
    """
    Description of the field
    """

    extend_edit_field_type: typing_extensions.Annotated[
        typing.Optional[EditJsonSchemaExtendEditFieldType], FieldMetadata(alias="extend_edit:field_type")
    ] = pydantic.Field(alias="extend_edit:field_type", default=None)
    """
    The PDF field type to edit. Allowed values depend on the schema type:
    * `["string", "null"]` → `text`, `signature`
    * `["number", "null"]` → `text`
    * `["integer", "null"]` → `text`
    * `["boolean", "null"]` → `checkbox`, `radio`
    * `"array"` → `text`, `table`
    * `"object"` → `signature`
    * enum fields (no type) → `radio`, `optionList`, `dropdown`
    """

    extend_edit_bbox: typing_extensions.Annotated[
        typing.Optional[EditBoundingBox], FieldMetadata(alias="extend_edit:bbox")
    ] = pydantic.Field(alias="extend_edit:bbox", default=None)
    extend_edit_page_index: typing_extensions.Annotated[
        typing.Optional[int], FieldMetadata(alias="extend_edit:page_index")
    ] = pydantic.Field(alias="extend_edit:page_index", default=None)
    """
    Zero-based page index where the field should be placed
    """

    extend_edit_text_edit_options: typing_extensions.Annotated[
        typing.Optional[EditTextOptions], FieldMetadata(alias="extend_edit:text_edit_options")
    ] = pydantic.Field(alias="extend_edit:text_edit_options", default=None)
    extend_edit_column_width: typing_extensions.Annotated[
        typing.Optional[float], FieldMetadata(alias="extend_edit:column_width")
    ] = pydantic.Field(alias="extend_edit:column_width", default=None)
    """
    Width of the column as a percentage (for table fields)
    """

    extend_edit_value: typing_extensions.Annotated[
        typing.Optional[typing.Any], FieldMetadata(alias="extend_edit:value")
    ] = pydantic.Field(alias="extend_edit:value", default=None)
    """
    The value to fill into this field. Can be any type. This will force the value at this field to be filled with this value. If a value is not provided, we will attempt to generate or infer one based on the instructions.
    """

    extend_edit_row_heights: typing_extensions.Annotated[
        typing.Optional[typing.List[float]], FieldMetadata(alias="extend_edit:row_heights")
    ] = pydantic.Field(alias="extend_edit:row_heights", default=None)
    """
    Array of row height percentages for array/table fields (e.g. [0.25, 0.50, 0.25])
    """

    items: typing.Optional["EditObjectJsonSchema"] = pydantic.Field(default=None)
    """
    Schema for array items (when type is "array"). Must be an EditObjectJSONSchema.
    """

    properties: typing.Optional[typing.Dict[str, "EditJsonSchema"]] = pydantic.Field(default=None)
    """
    Nested properties for object types. Each property follows the EditJSONSchema structure.
    """

    enum: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Allowed values for enum/dropdown/radio fields
    """

    max_items: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="maxItems")] = pydantic.Field(
        alias="maxItems", default=None
    )
    """
    Maximum number of rows for array/table fields
    """

    required: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    List of required property names (for object types)
    """

    additional_properties: typing_extensions.Annotated[
        typing.Optional[bool], FieldMetadata(alias="additionalProperties")
    ] = pydantic.Field(alias="additionalProperties", default=None)
    """
    Whether additional properties are allowed (for object types)
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow


from .edit_object_json_schema import EditObjectJsonSchema  # noqa: E402, I001

update_forward_refs(EditJsonSchema, EditObjectJsonSchema=EditObjectJsonSchema)
