{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://shotpup.com/data-format/shotpup-journal-backup-v1.schema.json",
  "title": "ShotPup journal backup",
  "description": "Manual JSON backup from the ShotPup iOS app (Settings → Export JSON backup). User-entered log data only; no device identifiers or auth tokens.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "exportedAt",
    "generator",
    "settings",
    "medications",
    "protocols",
    "shots",
    "sideEffects",
    "weights",
    "measurements",
    "supplies",
    "inventoryTransactions",
    "scheduleActions"
  ],
  "properties": {
    "schemaVersion": { "const": 1 },
    "exportedAt": { "type": "string", "format": "date-time" },
    "generator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["app", "platform"],
      "properties": {
        "app": { "const": "ShotPup" },
        "platform": { "const": "ios" }
      }
    },
    "settings": { "$ref": "#/$defs/settings" },
    "medications": { "type": "array", "items": { "$ref": "#/$defs/medication" } },
    "protocols": { "type": "array", "items": { "$ref": "#/$defs/protocol" } },
    "shots": { "type": "array", "items": { "$ref": "#/$defs/shot" } },
    "sideEffects": { "type": "array", "items": { "$ref": "#/$defs/sideEffect" } },
    "weights": { "type": "array", "items": { "$ref": "#/$defs/weight" } },
    "measurements": { "type": "array", "items": { "$ref": "#/$defs/measurement" } },
    "supplies": { "type": "array", "items": { "$ref": "#/$defs/supply" } },
    "inventoryTransactions": { "type": "array", "items": { "$ref": "#/$defs/inventoryTransaction" } },
    "scheduleActions": { "type": "array", "items": { "$ref": "#/$defs/scheduleAction" } }
  },
  "$defs": {
    "doseUnit": { "type": "string", "enum": ["mg", "mcg", "IU", "mL", "units"] },
    "isoDateTime": { "type": "string", "format": "date-time" },
    "localDate": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "onboarded",
        "lockEnabled",
        "discreetReminders",
        "celebratedMilestone",
        "celebratedEarlyMilestones",
        "firstOpenAt",
        "lastForegroundAt",
        "welcomeBackAbsenceKey",
        "reviewLastAskedAt",
        "reviewLastAskedVersion",
        "reviewAskCount",
        "firstRunChecklistHidden",
        "firstRunChecklistCompleteAcknowledged",
        "firstRunChecklistAsNeededChosen",
        "reminderPrimerDeclinedAt",
        "checklistStepsAnalyticsEmitted",
        "healthConsent",
        "cloudSyncConsent",
        "onboardingProfile"
      ],
      "properties": {
        "onboarded": { "type": "boolean" },
        "lockEnabled": { "type": "boolean" },
        "discreetReminders": { "type": "boolean" },
        "celebratedMilestone": { "type": "number" },
        "celebratedEarlyMilestones": { "type": "array", "items": { "type": "number" } },
        "firstOpenAt": { "type": ["string", "null"] },
        "lastForegroundAt": { "type": ["string", "null"], "format": "date-time" },
        "welcomeBackAbsenceKey": { "type": ["string", "null"] },
        "reviewLastAskedAt": { "type": ["string", "null"] },
        "reviewLastAskedVersion": { "type": ["string", "null"] },
        "reviewAskCount": { "type": "number" },
        "firstRunChecklistHidden": { "type": "boolean" },
        "firstRunChecklistCompleteAcknowledged": { "type": "boolean" },
        "firstRunChecklistAsNeededChosen": { "type": "boolean" },
        "reminderPrimerDeclinedAt": { "type": ["string", "null"] },
        "checklistStepsAnalyticsEmitted": {
          "type": "array",
          "items": { "type": "string", "enum": ["plan", "first_log", "reminders"] }
        },
        "healthConsent": { "$ref": "#/$defs/healthConsent" },
        "cloudSyncConsent": { "$ref": "#/$defs/cloudSyncConsent" },
        "onboardingProfile": { "type": "object" },
        "inventoryNeedsRecount": { "type": "boolean" }
      }
    },
    "healthConsent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["consentedAt", "withdrawnAt", "source", "version", "history"],
      "properties": {
        "consentedAt": { "type": ["string", "null"] },
        "withdrawnAt": { "type": ["string", "null"] },
        "source": { "type": ["string", "null"], "enum": ["onboarding", "settings", null] },
        "version": { "type": ["string", "null"] },
        "history": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["consentedAt", "withdrawnAt", "source", "version"],
            "properties": {
              "consentedAt": { "type": "string" },
              "withdrawnAt": { "type": ["string", "null"] },
              "source": { "type": ["string", "null"], "enum": ["onboarding", "settings", null] },
              "version": { "type": ["string", "null"] }
            }
          }
        }
      }
    },
    "cloudSyncConsent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["consentedAt", "withdrawnAt", "source", "version"],
      "properties": {
        "consentedAt": { "type": ["string", "null"] },
        "withdrawnAt": { "type": ["string", "null"] },
        "source": { "type": ["string", "null"], "enum": ["sign_in", null] },
        "version": { "type": ["string", "null"] }
      }
    },
    "medication": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "catalogSlug",
        "halfLifeHours",
        "tmaxHours",
        "halfLifeNote",
        "preferredDoseUnit",
        "mixedConcentrationMgPerMl"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string" },
        "catalogSlug": { "type": ["string", "null"] },
        "halfLifeHours": { "type": ["number", "null"] },
        "tmaxHours": { "type": ["number", "null"] },
        "halfLifeNote": { "type": ["string", "null"] },
        "preferredDoseUnit": { "anyOf": [{ "$ref": "#/$defs/doseUnit" }, { "type": "null" }] },
        "mixedConcentrationMgPerMl": { "type": ["number", "null"] }
      }
    },
    "protocol": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id", "compoundId", "tz", "active", "anchorMode", "effectiveFrom", "rule", "timeOfDay"],
      "properties": {
        "id": { "type": "string" },
        "compoundId": { "type": "string" },
        "tz": { "type": "string" },
        "active": { "type": "boolean" },
        "anchorMode": { "const": "original_day" },
        "effectiveFrom": { "$ref": "#/$defs/localDate" },
        "doseAmount": { "type": ["number", "null"] },
        "doseUnit": { "anyOf": [{ "$ref": "#/$defs/doseUnit" }, { "type": "null" }] },
        "reminderOnly": { "type": "boolean" },
        "rule": { "type": "object" },
        "timeOfDay": { "type": "array", "items": { "type": "string" } }
      }
    },
    "shot": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "recordedAt",
        "loggedAt",
        "localDate",
        "timeZone",
        "protocolId",
        "medicationId",
        "medicationName",
        "amount",
        "amountUnit",
        "notes",
        "injectionSiteCode",
        "legacy",
        "scheduleSlotAt",
        "deletedAt"
      ],
      "properties": {
        "id": { "type": "string" },
        "recordedAt": { "$ref": "#/$defs/isoDateTime" },
        "loggedAt": { "$ref": "#/$defs/isoDateTime" },
        "localDate": { "$ref": "#/$defs/localDate" },
        "timeZone": { "type": "string" },
        "protocolId": { "type": ["string", "null"] },
        "medicationId": { "type": ["string", "null"] },
        "medicationName": { "type": "string" },
        "amount": { "type": ["number", "null"] },
        "amountUnit": { "anyOf": [{ "$ref": "#/$defs/doseUnit" }, { "type": "null" }] },
        "notes": { "type": "string" },
        "injectionSiteCode": { "type": ["string", "null"] },
        "painLevel": { "type": ["integer", "null"], "minimum": 0, "maximum": 10 },
        "legacy": { "type": "boolean" },
        "scheduleSlotAt": { "type": ["string", "null"], "format": "date-time" },
        "deletedAt": { "type": ["string", "null"], "format": "date-time" }
      }
    },
    "sideEffect": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "recordedAt", "loggedAt", "localDate", "timeZone", "code", "severity", "notes"],
      "properties": {
        "id": { "type": "string" },
        "recordedAt": { "$ref": "#/$defs/isoDateTime" },
        "loggedAt": { "$ref": "#/$defs/isoDateTime" },
        "localDate": { "$ref": "#/$defs/localDate" },
        "timeZone": { "type": "string" },
        "code": { "type": "string" },
        "severity": { "type": "integer", "minimum": 1, "maximum": 5 },
        "notes": { "type": "string" }
      }
    },
    "weight": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "recordedAt", "loggedAt", "localDate", "timeZone", "value", "unit"],
      "properties": {
        "id": { "type": "string" },
        "recordedAt": { "$ref": "#/$defs/isoDateTime" },
        "loggedAt": { "$ref": "#/$defs/isoDateTime" },
        "localDate": { "$ref": "#/$defs/localDate" },
        "timeZone": { "type": "string" },
        "value": { "type": "number", "exclusiveMinimum": 0 },
        "unit": { "type": "string", "enum": ["kg", "lb"] }
      }
    },
    "measurement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "recordedAt", "loggedAt", "localDate", "timeZone", "kind", "value", "unit"],
      "properties": {
        "id": { "type": "string" },
        "recordedAt": { "$ref": "#/$defs/isoDateTime" },
        "loggedAt": { "$ref": "#/$defs/isoDateTime" },
        "localDate": { "$ref": "#/$defs/localDate" },
        "timeZone": { "type": "string" },
        "kind": { "type": "string" },
        "value": { "type": "number" },
        "unit": { "type": "string" }
      }
    },
    "supply": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "kind", "remaining", "unit", "lowAt", "refillOn"],
      "properties": {
        "id": { "type": "string" },
        "label": { "type": "string" },
        "kind": { "type": "string", "enum": ["vial", "pen"] },
        "remaining": { "type": "number" },
        "unit": { "$ref": "#/$defs/doseUnit" },
        "lowAt": { "type": ["number", "null"] },
        "refillOn": { "type": ["string", "null"] },
        "inventoryOverDraw": { "type": "boolean" }
      }
    },
    "inventoryTransaction": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "supplyId",
        "kind",
        "deltaMg",
        "deltaMl",
        "doseEventId",
        "at",
        "recordedAt",
        "deletedAt",
        "reversesId",
        "correctionId"
      ],
      "properties": {
        "id": { "type": "string" },
        "supplyId": { "type": "string" },
        "kind": { "type": "string" },
        "deltaMg": { "type": ["number", "null"] },
        "deltaMl": { "type": ["number", "null"] },
        "doseEventId": { "type": ["string", "null"] },
        "at": { "$ref": "#/$defs/isoDateTime" },
        "recordedAt": { "$ref": "#/$defs/isoDateTime" },
        "deletedAt": { "type": ["string", "null"], "format": "date-time" },
        "reversesId": { "type": ["string", "null"] },
        "correctionId": { "type": ["string", "null"] },
        "marksEmpty": { "type": "boolean" },
        "localDate": { "$ref": "#/$defs/localDate" },
        "timeZone": { "type": "string" }
      }
    },
    "scheduleAction": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "recordedAt",
        "protocolId",
        "scheduleSlotAt",
        "localDate",
        "timeZone",
        "status",
        "reasonCode",
        "notes",
        "deletedAt"
      ],
      "properties": {
        "id": { "type": "string" },
        "recordedAt": { "$ref": "#/$defs/isoDateTime" },
        "protocolId": { "type": "string" },
        "scheduleSlotAt": { "$ref": "#/$defs/isoDateTime" },
        "localDate": { "$ref": "#/$defs/localDate" },
        "timeZone": { "type": "string" },
        "status": { "const": "skipped" },
        "reasonCode": {
          "type": ["string", "null"],
          "enum": ["travel", "side_effects", "forgot", "other", null]
        },
        "notes": { "type": "string" },
        "deletedAt": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
