{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://harnery.com/schemas/docs-metadata-v2.schema.json",
  "title": "Harnery Markdown metadata v2",
  "type": "object",
  "required": [
    "schema",
    "type",
    "created_at",
    "updated_at",
    "summary"
  ],
  "properties": {
    "schema": {
      "const": "harnery-doc/v2"
    },
    "type": {
      "enum": [
        "plan",
        "issue",
        "handoff",
        "runbook",
        "topic",
        "audit",
        "book",
        "entity",
        "concept",
        "query",
        "page",
        "inquiry",
        "quote-sheet",
        "weekly-post",
        "synced-page"
      ]
    },
    "created_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "updated_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "owner": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "summary": {
      "type": "string",
      "minLength": 1
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
      },
      "uniqueItems": true
    },
    "relations": {
      "type": "object",
      "properties": {
        "depends_on": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "supersedes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "superseded_by": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "continues": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "related": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "access": {
      "type": "object",
      "properties": {
        "roles": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "viewers": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "status": {
      "type": "string"
    },
    "status_changed_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "status_note": {
      "type": "string",
      "minLength": 1
    },
    "severity": {
      "enum": [
        "low",
        "medium",
        "high",
        "critical"
      ]
    },
    "resolved_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "affected": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "resolution": {
      "type": "object",
      "required": [
        "outcome"
      ],
      "properties": {
        "outcome": {
          "type": "string",
          "minLength": 1
        },
        "commits": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "audience": {
      "type": "string",
      "minLength": 1
    },
    "source": {
      "type": "string",
      "minLength": 1
    },
    "reviewed_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "review_due_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "category": {
      "type": "string",
      "minLength": 1
    },
    "aliases": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "source_count": {
      "type": "integer",
      "minimum": 0
    },
    "provenance": {
      "type": "object",
      "required": [
        "sources"
      ],
      "properties": {
        "sources": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "primary_entity": {
      "type": "string"
    },
    "source_pages": {},
    "source_tokens": {},
    "top_entities": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "handle": {
      "type": "string",
      "minLength": 1
    },
    "published": {
      "type": "boolean"
    },
    "source_updated_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "source_id": {
      "type": "string",
      "minLength": 1
    },
    "source_template": {
      "type": "string",
      "minLength": 1
    },
    "product": {},
    "variant": {},
    "sku": {},
    "manufacturer": {},
    "customer": {},
    "bid_id": {},
    "drive_file_id": {},
    "drive_title": {},
    "quote_date": {},
    "revision": {},
    "batch_size": {},
    "order_size": {},
    "price": {},
    "source_pdf": {},
    "claims": {},
    "week": {},
    "coverage": {}
  },
  "patternProperties": {
    "^x_": {}
  },
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "plan"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "status",
          "status_changed_at",
          "owner"
        ],
        "properties": {
          "status": {
            "enum": [
              "proposed",
              "in-progress",
              "shipped",
              "abandoned"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "issue"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "status",
          "status_changed_at",
          "owner",
          "severity"
        ],
        "properties": {
          "status": {
            "enum": [
              "open",
              "resolved",
              "wontfix"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "handoff"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "status",
          "status_changed_at",
          "owner"
        ],
        "properties": {
          "status": {
            "enum": [
              "open",
              "resolved",
              "abandoned"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "runbook"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "owner",
          "reviewed_at",
          "review_due_at"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "enum": [
              "book",
              "entity",
              "concept",
              "query",
              "page"
            ]
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "title",
          "category",
          "source_count",
          "provenance"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "synced-page"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "title",
          "handle",
          "published",
          "source",
          "source_updated_at"
        ]
      }
    }
  ]
}
