{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://tantrafiles.xyz/schema/common.json",
 "title": "Wiser common definitions",
 "$defs": {
  "slug": {
   "type": "string",
   "pattern": "^[a-z0-9][a-z0-9-]{0,79}$",
   "description": "Lowercase ASCII slug. Never reused for a different thing; renames keep the old slug as an alias."
  },
  "topicPath": {
   "type": "string",
   "pattern": "^[a-z0-9][a-z0-9-]*(/[a-z0-9][a-z0-9-]*){0,3}$",
   "description": "Slash path root/leaf/subleaf, e.g. rebirth/bardo."
  },
  "clipId": {
   "type": "string",
   "pattern": "^[A-Za-z0-9_-]{11}(@[0-9]{1,6})?$",
   "description": "YouTube video id, or videoId@startSeconds for a virtual clip (a passage of a longer official video)."
  },
  "gid": {
   "type": "string",
   "pattern": "^(person|tradition|clip|text|practice|topic|collection|place|event|edge|curation|essay|user)/.+$",
   "description": "Global id = <kind>/<local id>. Also the canonical URL path: https://tantrafiles.xyz/<gid>."
  },
  "url": {
   "type": "string",
   "format": "uri"
  },
  "date": {
   "type": "string",
   "pattern": "^[0-9]{4}(-[0-9]{2}(-[0-9]{2})?)?$"
  },
  "wikidata": {
   "type": "string",
   "pattern": "^Q[0-9]+$"
  },
  "fuzzyTime": {
   "type": "object",
   "description": "Years as integers, negative = BCE. basis says whose dating it is.",
   "properties": {
    "start": {
     "type": [
      "integer",
      "null"
     ]
    },
    "end": {
     "type": [
      "integer",
      "null"
     ]
    },
    "precision": {
     "type": "string",
     "enum": [
      "day",
      "year",
      "decade",
      "century",
      "millennium"
     ]
    },
    "basis": {
     "type": "string",
     "enum": [
      "documented",
      "scholarly",
      "traditional",
      "estimate"
     ]
    },
    "label": {
     "type": "string",
     "description": "Human label, e.g. 'c. 1925–1988' or '6th–5th c. BCE'."
    },
    "alt": {
     "type": "string",
     "description": "Traditional or rival dating, shown alongside."
    }
   }
  },
  "source": {
   "type": "object",
   "required": [
    "url"
   ],
   "properties": {
    "url": {
     "$ref": "#/$defs/url"
    },
    "cite": {
     "type": "string"
    },
    "checked": {
     "$ref": "#/$defs/date"
    },
    "check": {
     "type": "string",
     "enum": [
      "work",
      "cited",
      "mentioned",
      "unverified",
      "needs_source",
      "reviewed"
     ]
    },
    "licence": {
     "type": "string",
     "description": "Licence of the SOURCE page, e.g. CC-BY-SA-4.0, CC-BY-NC-ND-4.0, publisher-free, all-rights-reserved."
    }
   }
  },
  "image": {
   "type": "object",
   "required": [
    "src"
   ],
   "properties": {
    "src": {
     "$ref": "#/$defs/url"
    },
    "face": {
     "$ref": "#/$defs/url"
    },
    "page": {
     "$ref": "#/$defs/url"
    },
    "artist": {
     "type": "string"
    },
    "license": {
     "type": "string"
    },
    "licenseUrl": {
     "$ref": "#/$defs/url"
    }
   }
  },
  "ids": {
   "type": "object",
   "description": "External identifiers (sameAs).",
   "properties": {
    "wikidata": {
     "$ref": "#/$defs/wikidata"
    },
    "viaf": {
     "type": "string"
    },
    "orcid": {
     "type": "string",
     "pattern": "^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$"
    },
    "openpatala": {
     "type": "string"
    },
    "atlas": {
     "type": "string"
    },
    "enwiki": {
     "type": "string"
    },
    "osm": {
     "type": "string"
    },
    "doi": {
     "type": "string"
    },
    "isbn": {
     "type": "string"
    },
    "youtube_channel": {
     "type": "string"
    }
   },
   "additionalProperties": {
    "type": "string"
   }
  },
  "links": {
   "type": "array",
   "items": {
    "type": "object",
    "required": [
     "url"
    ],
    "properties": {
     "label": {
      "type": "string"
     },
     "url": {
      "$ref": "#/$defs/url"
     },
     "kind": {
      "type": "string",
      "enum": [
       "official",
       "books",
       "retreats",
       "contact",
       "wikipedia",
       "channel",
       "other"
      ]
     }
    }
   }
  },
  "visibility": {
   "type": "string",
   "enum": [
    "public",
    "unlisted",
    "private"
   ]
  },
  "status": {
   "type": "string",
   "enum": [
    "draft",
    "review",
    "live",
    "retired"
   ]
  },
  "meta": {
   "type": "object",
   "description": "Record bookkeeping.",
   "properties": {
    "created": {
     "type": "string"
    },
    "updated": {
     "type": "string"
    },
    "status": {
     "$ref": "#/$defs/status"
    },
    "aliases": {
     "type": "array",
     "items": {
      "type": "string"
     }
    },
    "sources": {
     "type": "array",
     "items": {
      "$ref": "#/$defs/source"
     }
    },
    "confidence": {
     "type": "string",
     "enum": [
      "high",
      "medium",
      "low"
     ]
    },
    "license": {
     "type": "string",
     "description": "Licence of THIS record's metadata. Wiser curation: CC-BY-4.0."
    }
   }
  },
  "ref": {
   "type": "object",
   "required": [
    "id"
   ],
   "description": "A typed pointer to another record, with an optional note.",
   "properties": {
    "id": {
     "$ref": "#/$defs/gid"
    },
    "note": {
     "type": "string"
    },
    "start": {
     "type": "integer",
     "minimum": 0
    },
    "end": {
     "type": "integer",
     "minimum": 0
    }
   }
  },
  "duration": {
   "type": "object",
   "description": "Minutes. Use min=max for a fixed length.",
   "properties": {
    "min": {
     "type": "number",
     "minimum": 0
    },
    "max": {
     "type": "number",
     "minimum": 0
    },
    "default": {
     "type": "number",
     "minimum": 0
    }
   }
  }
 }
}
