{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.42todo.com/schemas/export/v1.json",
  "title": "42 Todo! Export Format v1",
  "description": "Portable export of a 42 Todo! account's spaces and tasks. See https://www.42todo.com/developers/export-format.",
  "type": "object",
  "required": ["format", "version", "exportedAt", "spaces", "tasks"],
  "properties": {
    "$schema": { "type": "string" },
    "format": { "const": "42todo-export" },
    "version": { "const": 1 },
    "exportedAt": { "$ref": "#/$defs/instant" },
    "generator": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": { "type": "string" },
        "version": { "type": "string" },
        "url": { "type": "string" }
      }
    },
    "spaces": {
      "type": "array",
      "items": { "$ref": "#/$defs/space" }
    },
    "tasks": {
      "type": "array",
      "items": { "$ref": "#/$defs/task" }
    },
    "ext": { "$ref": "#/$defs/ext" }
  },
  "$defs": {
    "instant": {
      "type": "string",
      "description": "RFC 3339 UTC instant",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"
    },
    "ext": {
      "type": "object",
      "description": "Vendor extensions, keyed by namespace (e.g. reverse-DNS). Unknown namespaces are ignored.",
      "additionalProperties": true
    },
    "space": {
      "type": "object",
      "required": ["id", "name", "type"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1, "maxLength": 100 },
        "type": { "enum": ["personal", "work", "project", "general"] },
        "system": { "type": "boolean", "default": false },
        "createdAt": { "$ref": "#/$defs/instant" },
        "updatedAt": { "$ref": "#/$defs/instant" },
        "ext": { "$ref": "#/$defs/ext" }
      },
      "if": {
        "properties": { "type": { "const": "general" } }
      },
      "then": {
        "properties": { "system": { "const": true } },
        "required": ["system"]
      }
    },
    "task": {
      "type": "object",
      "required": ["title"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1, "maxLength": 200 },
        "notes": { "type": "string", "maxLength": 4000 },
        "completed": { "type": "boolean", "default": false },
        "dueDate": {
          "type": "string",
          "description": "Floating calendar date (no timezone). Must also survive a calendar round-trip; the pattern alone cannot reject 2026-02-30.",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "dueTime": {
          "type": "string",
          "description": "Floating wall-clock time (no timezone). Only valid alongside dueDate.",
          "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
        },
        "space": {
          "type": ["string", "null"],
          "description": "Reference to spaces[].id in this document. Absent or null means the default (system) space."
        },
        "createdAt": { "$ref": "#/$defs/instant" },
        "updatedAt": { "$ref": "#/$defs/instant" },
        "ext": { "$ref": "#/$defs/ext" }
      },
      "dependentRequired": {
        "dueTime": ["dueDate"]
      }
    }
  }
}
