{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://thewarrecord.com/api/v1/schema/media.json",
 "title": "media",
 "type": "object",
 "description": "An openly licensed image we host, tied to the records it shows (Proposal 2026-11-03, the media archive). An image is a claim by whoever released it, never evidence: it raises no grade. Its licence must be on data-src/media/allowlist.json.",
 "required": [
  "id",
  "type",
  "kind",
  "file",
  "source_url",
  "allowlist",
  "licence",
  "credit",
  "released_by",
  "depicts",
  "warning",
  "published_at",
  "revision",
  "history",
  "record_state",
  "schema_version"
 ],
 "properties": {
  "record_state": {
   "enum": [
    "active",
    "merged",
    "withdrawn"
   ]
  },
  "merged_into": {
   "type": "string"
  },
  "withdrawn_reason": {
   "type": "string"
  },
  "schema_version": {
   "const": 1
  },
  "created_at": {
   "type": "string",
   "format": "date-time"
  },
  "last_changed": {
   "type": "string",
   "format": "date-time"
  },
  "id": {
   "type": "string",
   "pattern": "^me-\\d{8}-[0-9a-hjkmnp-tv-z]{4}$"
  },
  "type": {
   "const": "media"
  },
  "kind": {
   "enum": [
    "photo",
    "video_still",
    "satellite"
   ]
  },
  "file": {
   "type": "object",
   "description": "The copy we host. key is its name in the media store; its public address comes from mediaUrl in src/lib/urls.mjs.",
   "required": [
    "key",
    "sha256",
    "format"
   ],
   "properties": {
    "key": {
     "type": "string",
     "pattern": "^[a-z0-9][a-z0-9/._-]*$"
    },
    "sha256": {
     "type": "string",
     "pattern": "^[0-9a-f]{64}$"
    },
    "format": {
     "enum": [
      "jpeg",
      "png",
      "webp"
     ]
    },
    "bytes": {
     "type": "integer",
     "minimum": 1
    },
    "width": {
     "type": "integer",
     "minimum": 1
    },
    "height": {
     "type": "integer",
     "minimum": 1
    }
   },
   "additionalProperties": false
  },
  "source_url": {
   "type": "string",
   "format": "uri",
   "description": "Where the source published it."
  },
  "allowlist": {
   "type": "string",
   "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$",
   "description": "The allowlist entry it came through."
  },
  "licence": {
   "type": "string",
   "minLength": 3,
   "description": "The exact licence name and version, as the allowlist gives it (for example \"CC BY 4.0\")."
  },
  "licence_url": {
   "type": "string",
   "format": "uri"
  },
  "credit": {
   "type": "string",
   "minLength": 3,
   "description": "The credit as the licence requires it."
  },
  "released_by": {
   "type": "string",
   "description": "The body that published it, from the allowlist entry. Every image is labelled this way, whichever party released it."
  },
  "taken_on": {
   "type": "string",
   "format": "date",
   "description": "Only when the source states it."
  },
  "place": {
   "type": "string",
   "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$",
   "description": "Only when the source states it."
  },
  "depicts": {
   "type": "array",
   "items": {
    "type": "string",
    "pattern": "^(ev|st)-\\d{8}-[0-9a-hjkmnp-tv-z]{4}$"
   },
   "description": "The events or statements it shows. A depiction never counts towards a grade."
  },
  "warning": {
   "type": "boolean",
   "description": "true: shown only behind a warning the reader opens (graphic content)."
  },
  "flags": {
   "type": "array",
   "uniqueItems": true,
   "items": {
    "enum": [
     "dead",
     "badly_injured",
     "graphic",
     "identifiable_victim",
     "pow"
    ]
   },
   "description": "What the image shows that the gate rules on: dead, badly_injured and graphic need the warning; identifiable_victim and pow are never stored."
  },
  "published_at": {
   "type": "string",
   "format": "date-time"
  },
  "revision": {
   "type": "integer",
   "minimum": 1
  },
  "history": {
   "type": "array",
   "items": {
    "type": "object",
    "required": [
     "at",
     "batch",
     "field",
     "from",
     "to",
     "reason"
    ],
    "properties": {
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "batch": {
      "type": "string",
      "minLength": 3
     },
     "field": {
      "type": "string"
     },
     "from": {},
     "to": {},
     "rule": {
      "type": "string"
     },
     "reason": {
      "type": "string",
      "minLength": 3
     },
     "citations": {
      "type": "array",
      "items": {
       "type": "integer",
       "minimum": 0
      }
     }
    },
    "additionalProperties": false
   }
  }
 },
 "additionalProperties": false
}
