{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "devon.progress_rule_contract.schema.v1",
  "title": "DEVON Progress Rule Contract Schema",
  "description": "Schema for contracted progress checkpoints used to calculate item, category, phase and global progress from observable evidence only.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "progress_rule_contract_id",
    "version",
    "status",
    "item_id",
    "progress_mode",
    "fake_progress_forbidden",
    "checkpoints",
    "current_percent",
    "missing_to_100"
  ],
  "properties": {
    "progress_rule_contract_id": {
      "type": "string",
      "minLength": 1
    },
    "version": {
      "type": "string",
      "const": "v1"
    },
    "status": {
      "type": "string",
      "enum": ["DRAFT", "ACTIVE", "FAIL", "MISSING"]
    },
    "item_id": {
      "type": "string",
      "minLength": 1
    },
    "progress_mode": {
      "type": "string",
      "const": "contracted_checks"
    },
    "fake_progress_forbidden": {
      "type": "boolean",
      "const": true
    },
    "checkpoints": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/progress_checkpoint"
      }
    },
    "current_percent": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100
    },
    "missing_to_100": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/missing_record"
      }
    }
  },
  "$defs": {
    "progress_checkpoint": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "percent",
        "condition",
        "evidence_command",
        "evidence_type"
      ],
      "properties": {
        "percent": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "condition": {
          "type": "string"
        },
        "evidence_command": {
          "type": "string"
        },
        "evidence_type": {
          "type": "string"
        }
      }
    },
    "missing_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "missing_id",
        "description",
        "required_evidence",
        "blocking",
        "next_action"
      ],
      "properties": {
        "missing_id": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "required_evidence": {
          "type": "string"
        },
        "blocking": {
          "type": "boolean"
        },
        "next_action": {
          "type": "string"
        }
      }
    }
  }
}
