{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/garden-planner/backup-schema.json",
  "title": "Garden Planner backup",
  "description": "The file Garden Planner 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. Dates are YYYY-MM-DD. Bed sides and squares are whole numbers (1 square = 1 ft, or 30 cm in metric). Harvest amounts are a count, bunches, or whole grams for weights.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "seasons", "beds", "plants", "plantings", "harvests", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-garden-planner" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "seasons": { "type": "array", "items": { "$ref": "#/$defs/season" } },
    "beds": { "type": "array", "items": { "$ref": "#/$defs/bed" } },
    "plants": { "type": "array", "items": { "$ref": "#/$defs/plant" } },
    "plantings": { "type": "array", "items": { "$ref": "#/$defs/planting" } },
    "harvests": { "type": "array", "items": { "$ref": "#/$defs/harvest" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "season": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "year", "lastFrost", "firstFrost"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "year": { "type": "integer", "minimum": 2000, "maximum": 2100 },
        "lastFrost": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "firstFrost": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }
      }
    },
    "bed": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "width", "length", "sun", "notes"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "maxLength": 60 },
        "width": { "type": "integer", "minimum": 1, "maximum": 50 },
        "length": { "type": "integer", "minimum": 1, "maximum": 50 },
        "sun": { "enum": ["full", "part", "shade"] },
        "notes": { "type": "string", "maxLength": 1000 }
      }
    },
    "plant": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "category", "family", "dtm", "perSquare", "squaresEach", "indoors", "direct", "transplant", "tender", "anchor", "notes"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "maxLength": 60 },
        "category": { "enum": ["vegetable", "herb", "flower"] },
        "family": { "enum": ["nightshade", "squash", "legume", "cabbage", "carrot", "beet", "onion", "daisy", "grass", "mint", "mallow", "other"] },
        "dtm": { "type": "integer", "minimum": 1, "maximum": 400 },
        "perSquare": { "type": "integer", "minimum": 1, "maximum": 16 },
        "squaresEach": { "type": "integer", "minimum": 1, "maximum": 16 },
        "indoors": { "type": ["integer", "null"], "minimum": -200, "maximum": 200 },
        "direct": { "type": ["integer", "null"], "minimum": -200, "maximum": 200 },
        "transplant": { "type": ["integer", "null"], "minimum": -200, "maximum": 200 },
        "tender": { "type": "boolean" },
        "anchor": { "enum": ["spring", "fall"] },
        "notes": { "type": "string", "maxLength": 1000 }
      }
    },
    "planting": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "seasonId", "bedId", "plantId", "method", "squares", "sowDate", "plantOutDate", "status", "notes"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "seasonId": { "type": "string", "minLength": 1 },
        "bedId": { "type": ["string", "null"] },
        "plantId": { "type": "string", "minLength": 1 },
        "method": { "enum": ["indoors", "direct", "starts"] },
        "squares": { "type": "integer", "minimum": 1, "maximum": 2500 },
        "sowDate": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "plantOutDate": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "status": { "enum": ["planned", "started", "growing", "done"] },
        "notes": { "type": "string", "maxLength": 1000 }
      }
    },
    "harvest": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "plantingId", "day", "unit", "amount", "notes"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "plantingId": { "type": "string", "minLength": 1 },
        "day": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "unit": { "enum": ["each", "bunch", "lb", "oz", "kg", "g"] },
        "amount": { "type": "integer", "minimum": 1, "maximum": 999999 },
        "notes": { "type": "string", "maxLength": 1000 }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "units", "season"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "units": { "enum": ["us", "metric"] },
        "season": { "type": ["string", "null"] }
      }
    },
    "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" }
      }
    }
  }
}
