{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/pet-care/backup-schema.json",
  "title": "Pet Care backup",
  "description": "The file Pet Care 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. Money is in whole minor units (cents); weights are whole grams.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "pets", "tasks", "done", "vaccines", "visits", "weights", "expenses", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-pet-care" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "pets": { "type": "array", "maxItems": 50, "items": { "$ref": "#/$defs/pet" } },
    "tasks": { "type": "array", "maxItems": 400, "items": { "$ref": "#/$defs/task" } },
    "done": { "type": "array", "maxItems": 40000, "items": { "$ref": "#/$defs/done" } },
    "vaccines": { "type": "array", "maxItems": 1000, "items": { "$ref": "#/$defs/vaccine" } },
    "visits": { "type": "array", "maxItems": 2000, "items": { "$ref": "#/$defs/visit" } },
    "weights": { "type": "array", "maxItems": 5000, "items": { "$ref": "#/$defs/weight" } },
    "expenses": { "type": "array", "maxItems": 10000, "items": { "$ref": "#/$defs/expense" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "photoData": { "type": "object", "additionalProperties": { "type": "string" } },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "pet": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "species", "breed", "sex", "fixed", "born", "adopted", "color", "chip", "vet", "vetPhone", "allergies", "conditions", "diet", "notes", "photo", "archived", "added"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 40 },
        "species": { "enum": ["dog", "cat", "bird", "fish", "reptile", "small", "other"] },
        "breed": { "type": "string", "maxLength": 80 },
        "sex": { "enum": ["unknown", "female", "male"] },
        "fixed": { "type": ["boolean", "null"] },
        "born": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "adopted": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "color": { "type": "string", "maxLength": 80 },
        "chip": { "type": "string", "maxLength": 30 },
        "vet": { "type": "string", "maxLength": 80 },
        "vetPhone": { "type": "string", "maxLength": 30 },
        "allergies": { "type": "string", "maxLength": 300 },
        "conditions": { "type": "string", "maxLength": 1000 },
        "diet": { "type": "string", "maxLength": 300 },
        "notes": { "type": "string", "maxLength": 1000 },
        "photo": { "type": ["string", "null"] },
        "archived": { "type": "boolean" },
        "added": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }
      }
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "petId", "title", "category", "repeat", "every", "days", "times", "start", "paused", "notes", "added"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "petId": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "title": { "type": "string", "minLength": 1, "maxLength": 80 },
        "category": { "enum": ["feeding", "walk", "litter", "grooming", "nails", "flea", "heartworm", "meds", "other"] },
        "repeat": { "enum": ["daily", "weekdays", "days", "weeks", "months", "once"] },
        "every": { "type": "integer", "minimum": 1 },
        "days": { "type": "array", "items": { "type": "integer", "minimum": 0, "maximum": 6 } },
        "times": { "type": "array", "maxItems": 6, "items": { "type": "string", "pattern": "^[0-9]{2}:[0-9]{2}$" } },
        "start": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "paused": { "type": "boolean" },
        "notes": { "type": "string", "maxLength": 1000 },
        "added": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }
      }
    },
    "done": {
      "type": "object",
      "additionalProperties": false,
      "required": ["task", "date", "slot"],
      "properties": {
        "task": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "date": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "slot": { "type": "string" }
      }
    },
    "vaccine": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "petId", "name", "given", "due", "notes"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "petId": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "given": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "due": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "notes": { "type": "string", "maxLength": 300 }
      }
    },
    "visit": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "petId", "date", "clinic", "reason", "cost", "notes"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "petId": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "date": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "clinic": { "type": "string", "maxLength": 80 },
        "reason": { "type": "string", "maxLength": 80 },
        "cost": { "type": ["integer", "null"], "minimum": 0, "maximum": 100000000 },
        "notes": { "type": "string", "maxLength": 1000 }
      }
    },
    "weight": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "petId", "date", "grams"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "petId": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "date": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "grams": { "type": "integer", "minimum": 1, "maximum": 200000 }
      }
    },
    "expense": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "petId", "date", "category", "amount", "note"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,40}$" },
        "petId": { "type": ["string", "null"] },
        "date": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "category": { "enum": ["food", "vet", "meds", "grooming", "supplies", "toys", "boarding", "insurance", "other"] },
        "amount": { "type": "integer", "minimum": 0, "maximum": 100000000 },
        "note": { "type": "string", "maxLength": 80 }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "currency", "weightUnit", "soonDays", "includePhotos", "contactName", "contactPhone"],
      "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"] },
        "weightUnit": { "enum": ["kg", "lb"] },
        "soonDays": { "enum": [7, 14, 30, 60] },
        "includePhotos": { "type": "boolean" },
        "contactName": { "type": "string", "maxLength": 80 },
        "contactPhone": { "type": "string", "maxLength": 30 }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lastExport", "firstUse"],
      "properties": {
        "lastExport": { "type": ["string", "null"], "format": "date-time" },
        "firstUse": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
