{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/time-tracker/backup-schema.json",
  "title": "Time Tracker backup",
  "description": "The file Time Tracker 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. Times are Unix milliseconds; rates are minor units per hour.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "clients", "projects", "entries", "timer", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-time-tracker" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "clients": { "type": "array", "items": { "$ref": "#/$defs/client" } },
    "projects": { "type": "array", "items": { "$ref": "#/$defs/project" } },
    "entries": { "type": "array", "items": { "$ref": "#/$defs/entry" } },
    "timer": { "oneOf": [ { "type": "null" }, { "$ref": "#/$defs/timer" } ] },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "client": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "rate"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 60 },
        "rate": { "type": ["integer", "null"], "minimum": 1, "maximum": 100000000 }
      }
    },
    "project": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "clientId", "rate", "billable", "color", "archived"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 60 },
        "clientId": { "type": ["string", "null"] },
        "rate": { "type": ["integer", "null"], "minimum": 1, "maximum": 100000000 },
        "billable": { "type": "boolean" },
        "color": { "enum": ["teal", "blue", "violet", "rose", "amber", "green", "slate", "orange"] },
        "archived": { "type": "boolean" }
      }
    },
    "entry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "projectId", "start", "end", "note"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "projectId": { "type": "string", "minLength": 1 },
        "start": { "type": "integer", "minimum": 946684800000, "maximum": 4102444800000 },
        "end": { "type": "integer", "minimum": 946684800000, "maximum": 4102444800000 },
        "note": { "type": "string", "maxLength": 200 }
      }
    },
    "timer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["projectId", "start", "note"],
      "properties": {
        "projectId": { "type": "string", "minLength": 1 },
        "start": { "type": "integer", "minimum": 946684800000, "maximum": 4102444800000 },
        "note": { "type": "string", "maxLength": 200 }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "currency", "rounding", "roundMode", "weeklyGoal", "lastProject"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "currency": { "enum": ["USD", "EUR", "GBP", "CAD", "AUD", "NZD", "CHF", "SEK", "NOK", "DKK", "PLN", "MXN", "BRL", "INR", "ZAR", "SGD", "HKD", "JPY", "KRW"] },
        "rounding": { "enum": [0, 6, 15, 30] },
        "roundMode": { "enum": ["nearest", "up"] },
        "weeklyGoal": { "type": "integer", "minimum": 0, "maximum": 10080 },
        "lastProject": { "type": ["string", "null"] }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lastExport", "firstUse"],
      "properties": {
        "lastExport": { "type": ["string", "null"], "format": "date-time" },
        "firstUse": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
