{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/fuel-log/backup-schema.json",
  "title": "Fuel Log backup",
  "description": "The file Fuel Log 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. Odometer readings are tenths of a distance unit, fuel and charge are thousandths of a gallon, litre or kWh, and money is in minor units of the chosen currency (cents; whole yen). Days are YYYY-MM-DD.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "vehicles", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-fuel-log" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "vehicles": { "type": "array", "items": { "$ref": "#/$defs/vehicle" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "vehicle": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "units", "economy", "energy", "notes", "fills"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "maxLength": 60 },
        "units": { "enum": ["us", "metric", "ev-mi", "ev-km"] },
        "economy": { "enum": ["mpg", "l100", "kml", "mikwh", "kwh100", "kmkwh"] },
        "energy": { "enum": ["gasoline", "diesel", "hybrid", "electric", "other"] },
        "notes": { "type": "string", "maxLength": 500 },
        "fills": { "type": "array", "items": { "$ref": "#/$defs/fill" } }
      }
    },
    "fill": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "date", "odo", "amount", "cost", "full", "missed", "station", "notes"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "date": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "odo": { "type": "integer", "minimum": 0, "maximum": 99999999 },
        "amount": { "type": "integer", "minimum": 1, "maximum": 750000 },
        "cost": { "type": ["integer", "null"], "minimum": 0, "maximum": 10000000 },
        "full": { "type": "boolean" },
        "missed": { "type": "boolean" },
        "station": { "type": "string", "maxLength": 80 },
        "notes": { "type": "string", "maxLength": 500 }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "currency", "activeVehicle"],
      "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"] },
        "activeVehicle": { "type": "string" }
      }
    },
    "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" }
      }
    }
  }
}
