{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.mhb.software/idx/import.schema.json",
  "title": "Index export",
  "description": "Version 2 lists spaces, each with its groups, each with its links. Files from older versions (version 1, or no version) list workspaces, projects and tabs instead, in the same shape, and still import.",
  "type": "object",
  "oneOf": [
    {
      "description": "Version 2: spaces, groups and links.",
      "required": [
        "spaces"
      ],
      "properties": {
        "version": {
          "const": 2
        }
      }
    },
    {
      "description": "Version 1, from older versions: workspaces (spaces), projects (groups) and tabs (links).",
      "required": [
        "workspaces"
      ],
      "not": {
        "required": [
          "spaces"
        ]
      },
      "properties": {
        "version": {
          "const": 1
        }
      }
    }
  ],
  "properties": {
    "app": {
      "const": "tabs"
    },
    "version": {
      "enum": [
        1,
        2
      ],
      "description": "2 for files with spaces, groups and links; 1 (or none) for files with workspaces, projects and tabs."
    },
    "exportedAt": {
      "type": "string",
      "format": "date-time"
    },
    "spaces": {
      "type": "array",
      "description": "The spaces, in display order.",
      "items": {
        "$ref": "#/$defs/space"
      }
    },
    "workspaces": {
      "type": "array",
      "deprecated": true,
      "description": "Version 1's name for spaces. Read only when the file has no spaces.",
      "items": {
        "$ref": "#/$defs/workspace"
      }
    },
    "favorites": {
      "type": "array",
      "maxItems": 8,
      "description": "The pages that belong to no space, in the order of the strip. Left out, an import leaves the favorites as they are.",
      "items": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096,
            "description": "The address the favorite opens."
          },
          "title": {
            "type": "string",
            "maxLength": 80
          },
          "auto": {
            "type": "boolean",
            "description": "The title is the page's own, not one the user gave. Save current page replaces it with the new page's title; a title the user gave is kept."
          }
        }
      }
    }
  },
  "$defs": {
    "link": {
      "type": "object",
      "required": [
        "url"
      ],
      "properties": {
        "url": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096,
          "description": "The address the link is saved with."
        },
        "title": {
          "type": "string",
          "maxLength": 80
        },
        "auto": {
          "type": "boolean",
          "description": "The title is the page's own, not one the user gave. Save current page replaces it with the new page's title; a title the user gave is kept."
        },
        "latest": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096,
          "deprecated": true,
          "description": "Written by older versions for a link whose tab had moved on. Read as the link's address, in place of url. No longer written."
        }
      }
    },
    "space": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]{1,16}$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 60
        },
        "groups": {
          "type": "array",
          "description": "The space's groups, in display order.",
          "items": {
            "$ref": "#/$defs/group"
          }
        }
      }
    },
    "group": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]{1,16}$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 60
        },
        "color": {
          "enum": [
            "grey",
            "blue",
            "red",
            "yellow",
            "green",
            "pink",
            "purple",
            "cyan",
            "orange"
          ]
        },
        "links": {
          "type": "array",
          "description": "The group's links, in tab-strip order.",
          "items": {
            "$ref": "#/$defs/link"
          }
        }
      }
    },
    "workspace": {
      "type": "object",
      "required": [
        "name"
      ],
      "description": "A space, as version 1 wrote it.",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]{1,16}$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 60
        },
        "projects": {
          "type": "array",
          "description": "Version 1's name for groups.",
          "items": {
            "$ref": "#/$defs/project"
          }
        }
      }
    },
    "project": {
      "type": "object",
      "required": [
        "name"
      ],
      "description": "A group, as version 1 wrote it.",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]{1,16}$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 60
        },
        "color": {
          "enum": [
            "grey",
            "blue",
            "red",
            "yellow",
            "green",
            "pink",
            "purple",
            "cyan",
            "orange"
          ]
        },
        "tabs": {
          "type": "array",
          "description": "Version 1's name for links.",
          "items": {
            "$ref": "#/$defs/link"
          }
        }
      }
    }
  }
}
