{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://theamateur.co.uk/schemas/dpl/dpl.draft-gate-1.schema.json",
  "title": "DPL draft gate (dpl.draft-gate/1)",
  "description": "What `dpl draft gate <plan> --format json` writes: pass or fail for one revision of a plan, the reasons it failed, the state of each layer, the counts, and a certificate of what was checked and what was not. Every member listed here is always written, or left out when null; nothing else appears.",
  "$comment": "The command exits 0 on a pass and 7 on a fail. `result` is `ready_to_shoot` when `passed`. The certificate claims only what the gate did: editing craft and shoot feasibility under the rules named in `rules_version`, not whether the film is good.",
  "type": "object",
  "properties": {
    "format": {
      "type": "string",
      "const": "dpl.draft-gate/1"
    },
    "work_id": {
      "type": "string"
    },
    "profile": {
      "type": "string",
      "enum": [
        "film",
        "short"
      ]
    },
    "plan_hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "rules_version": {
      "type": "string"
    },
    "grammar_version": {
      "type": "string"
    },
    "passed": {
      "type": "boolean"
    },
    "result": {
      "description": "ready_to_shoot when the gate passed, not_ready when it did not.",
      "type": "string",
      "enum": [
        "ready_to_shoot",
        "not_ready"
      ]
    },
    "reasons": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/GateReason"
      }
    },
    "layers": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/GateLayer"
      }
    },
    "counts": {
      "$ref": "#/$defs/GateCounts"
    },
    "certificate": {
      "$ref": "#/$defs/GateCertificate"
    }
  },
  "required": [
    "format",
    "work_id",
    "profile",
    "plan_hash",
    "rules_version",
    "grammar_version",
    "passed",
    "result",
    "reasons",
    "layers",
    "counts",
    "certificate"
  ],
  "additionalProperties": false,
  "$defs": {
    "GateCertificate": {
      "type": "object",
      "description": "What the gate checked and what it did not. Worded to claim only what was done.",
      "properties": {
        "checked": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "not_checked": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "statement": {
          "type": "string"
        }
      },
      "required": [
        "checked",
        "not_checked",
        "statement"
      ],
      "additionalProperties": false
    },
    "GateCounts": {
      "type": "object",
      "properties": {
        "blocker": {
          "type": "integer",
          "minimum": 0
        },
        "major": {
          "type": "integer",
          "minimum": 0
        },
        "minor": {
          "type": "integer",
          "minimum": 0
        },
        "note": {
          "type": "integer",
          "minimum": 0
        },
        "overridden": {
          "type": "integer",
          "minimum": 0
        },
        "blocking_questions": {
          "type": "integer",
          "minimum": 0
        },
        "other_questions": {
          "type": "integer",
          "minimum": 0
        },
        "scenes_not_assessed": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "blocker",
        "major",
        "minor",
        "note",
        "overridden",
        "blocking_questions",
        "other_questions",
        "scenes_not_assessed"
      ],
      "additionalProperties": false
    },
    "GateLayer": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "applies": {
          "type": "boolean"
        },
        "complete": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "applies",
        "complete"
      ],
      "additionalProperties": false
    },
    "GateReason": {
      "type": "object",
      "properties": {
        "kind": {
          "$ref": "#/$defs/GateReasonKind"
        },
        "message": {
          "type": "string"
        },
        "layer": {
          "type": [
            "string",
            "null"
          ]
        },
        "path": {
          "type": [
            "string",
            "null"
          ]
        },
        "finding": {
          "description": "The finding's id and code, when the reason is a finding.",
          "type": [
            "string",
            "null"
          ],
          "pattern": "^f-[0-9a-f]{12}$"
        },
        "code": {
          "type": [
            "string",
            "null"
          ]
        },
        "fix": {
          "description": "What to do about it.",
          "type": "string"
        }
      },
      "required": [
        "kind",
        "message",
        "fix"
      ],
      "additionalProperties": false
    },
    "GateReasonKind": {
      "type": "string",
      "description": "Why the gate failed.",
      "enum": [
        "plan_error",
        "layer_incomplete",
        "placeholder",
        "open_blocker",
        "open_major",
        "blocking_question"
      ]
    }
  }
}
