{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title": "declare_entity_definition_command",
  "description": "Declare entity definition command schema.",
  "additionalProperties": false,
  "required": [
    "service_id",
    "entity_type",
    "title",
    "description",
    "entity_field_definitions"
  ],
  "properties": {
    "service_id": {
      "type": "string",
      "minLength": 1,
      "pattern": "^$|.*\\S.*",
      "description": "The string has a minimum length of one character and it cannot consist of only whitespace characters."
    },
    "entity_type": {
      "type": "string",
      "minLength": 1,
      "pattern": "^$|.*\\S.*",
      "description": "The string has a minimum length of one character and it cannot consist of only whitespace characters."
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "pattern": "^$|.*\\S.*",
      "description": "The string has a minimum length of one character and it cannot consist of only whitespace characters."
    },
    "description": {
      "type": "string",
      "description": "A description of the entity definition."
    },
    "is_archived": {
      "type": "boolean",
      "description": "Set to true if definition should be archived, and send a separate delete command after the definition is archived."
    },
    "entity_field_definitions": {
      "type": "array",
      "description": "An array of field definitions that belong to this entity definition.",
      "additionalItems": false,
      "items": {
        "type": "object",
        "title": "entity_field_definition",
        "description": "Definition of an entity field.",
        "additionalProperties": false,
        "required": [
          "field_name",
          "field_type",
          "ui_field_type"
        ],
        "properties": {
          "field_name": {
            "type": "string",
            "minLength": 1,
            "pattern": "^$|.*\\S.*",
            "description": "The string has a minimum length of one character and it cannot consist of only whitespace characters."
          },
          "field_type": {
            "type": "string",
            "title": "field_type",
            "enum": [
              "STRING"
            ],
            "description": "The data type of the field defined by this definition"
          },
          "ui_field_type": {
            "type": "string",
            "title": "ui_field_type",
            "enum": [
              "TEXTBOX",
              "TEXTAREA",
              "CUSTOM"
            ],
            "description": "The type of user interface element that should be used to display this field"
          },
          "title": {
            "type": "string",
            "description": "The title of the field definition"
          },
          "description": {
            "type": "string",
            "description": "A description of the field definition"
          },
          "sort_index": {
            "type": "integer",
            "description": "The order in which this field should be displayed in relation to other fields of the same entity"
          },
          "is_active": {
            "type": "boolean",
            "description": "Set to false if field definition should be deactivated, and send a separate declare command without the field after the field definition is deactivated to completely delete it."
          },
          "ui_field_custom_definition": {
            "type": "object",
            "title": "ui_field_custom_definition",
            "description": "Definition of custom Piral extension that should be used to display localization source value and translation editor field",
            "required": [
              "fallback_type"
            ],
            "properties": {
              "fallback_type": {
                "type": "string",
                "title": "ui_field_custom_definition_fallback_type",
                "enum": [
                  "TEXTBOX",
                  "TEXTAREA"
                ],
                "description": "The fallback type to use if the custom UI field type is not available"
              },
              "view": {
                "type": "object",
                "title": "ui_field_custom_definition_view",
                "description": "Configuration of the Piral extension used for viewing the source value",
                "additionalProperties": false,
                "properties": {
                  "component": {
                    "type": "string",
                    "description": "Piral extension name that will be used for viewing source value"
                  },
                  "props": {
                    "type": "object",
                    "title": "ui_field_custom_definition_view_props",
                    "description": "Additional properties and their values defined as key-value pairs that will be passed to the view component",
                    "additionalProperties": {
                      "oneOf": [
                        {
                          "type": "string",
                          "description": "A string property for the view component"
                        },
                        {
                          "type": "number",
                          "description": "A number property for the view component"
                        },
                        {
                          "type": "boolean",
                          "description": "A boolean property for the view component"
                        },
                        {
                          "type": "array",
                          "description": "A null property for the view component"
                        },
                        {
                          "type": "object",
                          "description": "An object property for the view component",
                          "additionalProperties": true
                        }
                      ]
                    }
                  },
                  "property_map": {
                    "type": "object",
                    "title": "ui_field_custom_definition_view_property_map",
                    "description": "Mapping of property names that will be passed from the localization form to the custom Piral extension for viewing the source value",
                    "properties": {
                      "value": {
                        "type": "string",
                        "description": "The name of the property that contains localization source value (defaults to 'value' if not provided)"
                      }
                    },
                    "additionalProperties": false
                  }
                },
                "required": [
                  "component"
                ]
              },
              "edit": {
                "type": "object",
                "title": "ui_field_custom_definition_edit",
                "description": "Configuration of the Piral extension used for editing the translated value",
                "additionalProperties": false,
                "properties": {
                  "component": {
                    "type": "string",
                    "description": "Custom Piral extension name that will be used for editing localization"
                  },
                  "props": {
                    "type": "object",
                    "title": "ui_field_custom_definition_edit_props",
                    "description": "Additional properties and their values defined as key-value pairs that will be passed to the edit component",
                    "additionalProperties": {
                      "oneOf": [
                        {
                          "type": "string",
                          "description": "A string property for the view component"
                        },
                        {
                          "type": "number",
                          "description": "A number property for the view component"
                        },
                        {
                          "type": "boolean",
                          "description": "A boolean property for the view component"
                        },
                        {
                          "type": "array",
                          "description": "A null property for the view component"
                        },
                        {
                          "type": "object",
                          "description": "An object property for the view component",
                          "additionalProperties": true
                        }
                      ]
                    }
                  },
                  "property_map": {
                    "type": "object",
                    "title": "ui_field_custom_definition_edit_property_map",
                    "description": "Mapping of property names that will be passed from the localization form to the custom Piral extension used for editing the localized value",
                    "properties": {
                      "locale": {
                        "type": "string",
                        "description": "The name of the property that contains the locale (defaults to 'locale' if not provided)"
                      },
                      "value": {
                        "type": "string",
                        "description": "The name of the property that contains the localized value (defaults to 'value' if not provided)"
                      },
                      "on_change": {
                        "type": "string",
                        "description": "The name of the property that contains the callback function that should be called when the value is changed (defaults to 'onChange' if not provided)"
                      }
                    },
                    "additionalProperties": false
                  }
                },
                "required": [
                  "component"
                ]
              }
            },
            "additionalProperties": false
          },
          "field_validation_rules": {
            "type": "array",
            "description": "An array of field validation rules.",
            "additionalItems": false,
            "items": {
              "type": "object",
              "title": "field_definition_validation_rule",
              "description": "Definition of an entity field validation rule.",
              "additionalProperties": false,
              "required": [
                "message",
                "settings",
                "type",
                "severity"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "title": "field_definition_field_validation_rule",
                  "enum": [
                    "LENGTH",
                    "REQUIRED",
                    "REGEX"
                  ],
                  "description": "The type of the validation rule."
                },
                "settings": {
                  "type": "object",
                  "title": "field_definition_validation_rule_settings",
                  "description": "Additional settings for the field validation rule."
                },
                "message": {
                  "type": "string",
                  "description": "The message to be displayed when validation fails for this rule."
                },
                "severity": {
                  "type": "string",
                  "title": "field_definition_validation_severity",
                  "enum": [
                    "ERROR",
                    "WARNING"
                  ],
                  "description": "Severity to be used if validation fails for this rule."
                }
              }
            }
          },
          "approval_behavior": {
            "type": "string",
            "title": "approval_behavior",
            "enum": [
              "REQUIRED",
              "REQUIRED_IF_NOT_EMPTY",
              "NOT_REQUIRED"
            ],
            "description": "Configuration of the approval behavior for the field"
          }
        }
      },
      "minItems": 1
    }
  }
}