{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://folio.mccal.dev/schema/v1/settings.schema.json",
  "title": "Folio package settings page",
  "type": "object",
  "required": [
    "format",
    "items"
  ],
  "additionalProperties": false,
  "$defs": {
    "item": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "enum": [
            "toggle",
            "picker",
            "segmented",
            "slider",
            "stepper",
            "color",
            "appPicker",
            "link",
            "page",
            "group"
          ]
        },
        "key": {
          "type": "string",
          "pattern": "^[a-zA-Z][a-zA-Z0-9_]{0,40}$"
        },
        "title": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 400
            },
            {
              "type": "object",
              "required": [
                "en"
              ],
              "propertyNames": {
                "pattern": "^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
              },
              "additionalProperties": {
                "type": "string",
                "minLength": 1,
                "maxLength": 400
              },
              "maxProperties": 64
            }
          ]
        },
        "footer": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 400
            },
            {
              "type": "object",
              "required": [
                "en"
              ],
              "propertyNames": {
                "pattern": "^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
              },
              "additionalProperties": {
                "type": "string",
                "minLength": 1,
                "maxLength": 400
              },
              "maxProperties": 64
            }
          ]
        },
        "default": {},
        "options": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "value",
              "title"
            ],
            "properties": {
              "value": {
                "type": [
                  "string",
                  "number",
                  "boolean"
                ]
              },
              "title": {
                "oneOf": [
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 400
                  },
                  {
                    "type": "object",
                    "required": [
                      "en"
                    ],
                    "propertyNames": {
                      "pattern": "^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
                    },
                    "additionalProperties": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 400
                    },
                    "maxProperties": 64
                  }
                ]
              }
            }
          }
        },
        "min": {
          "type": "number"
        },
        "max": {
          "type": "number"
        },
        "step": {
          "type": "number"
        },
        "url": {
          "type": "string",
          "pattern": "^https://\\S+$",
          "maxLength": 2048
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/item"
          }
        },
        "advanced": {
          "type": "boolean"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "toggle",
                  "picker",
                  "segmented",
                  "slider",
                  "stepper",
                  "color",
                  "appPicker"
                ]
              }
            }
          },
          "then": {
            "required": [
              "key",
              "title",
              "default"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "picker",
                  "segmented"
                ]
              }
            }
          },
          "then": {
            "required": [
              "options"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "slider",
                  "stepper"
                ]
              }
            }
          },
          "then": {
            "required": [
              "min",
              "max"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "link"
              }
            }
          },
          "then": {
            "required": [
              "title",
              "url"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "page",
                  "group"
                ]
              }
            }
          },
          "then": {
            "required": [
              "title",
              "items"
            ]
          }
        }
      ]
    }
  },
  "properties": {
    "$schema": {
      "type": "string"
    },
    "format": {
      "const": 1
    },
    "items": {
      "type": "array",
      "maxItems": 60,
      "items": {
        "$ref": "#/$defs/item"
      }
    }
  }
}
