{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/hydration/backup-schema.json",
  "title": "Hydration backup",
  "description": "The file Hydration writes when you choose Download backup. Every value stays on your device; this schema documents the exact shape so the data stays readable without the app. Every amount is a whole number of millilitres; fluid ounces are only for display. Times are minutes after midnight.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "entries", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-hydration" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "entries": { "type": "array", "items": { "$ref": "#/$defs/entry" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "entry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "at", "ml", "drink", "note"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "at": { "type": "integer", "minimum": 946684800000, "maximum": 4102444800000 },
        "ml": { "type": "integer", "minimum": 1, "maximum": 5000 },
        "drink": { "enum": ["water", "tea", "coffee", "milk", "juice", "soda", "other"] },
        "note": { "type": "string", "maxLength": 200 }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "unit", "goal", "counted", "wake", "sleep", "remind", "lastDrink", "cups"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "unit": { "enum": ["ml", "oz"] },
        "goal": { "type": "integer", "minimum": 0, "maximum": 10000 },
        "counted": { "type": "array", "items": { "enum": ["water", "tea", "coffee", "milk", "juice", "soda", "other"] } },
        "wake": { "type": "integer", "minimum": 0, "maximum": 1439 },
        "sleep": { "type": "integer", "minimum": 0, "maximum": 1439 },
        "remind": { "enum": [0, 30, 45, 60, 90, 120, 180] },
        "lastDrink": { "enum": ["water", "tea", "coffee", "milk", "juice", "soda", "other"] },
        "cups": { "type": "array", "minItems": 1, "maxItems": 8, "items": { "$ref": "#/$defs/cup" } }
      }
    },
    "cup": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "ml"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "maxLength": 24 },
        "ml": { "type": "integer", "minimum": 10, "maximum": 2000 }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lastExport", "firstUse", "welcomed"],
      "properties": {
        "lastExport": { "type": ["string", "null"], "format": "date-time" },
        "firstUse": { "type": ["string", "null"], "format": "date-time" },
        "welcomed": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
