{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wheelie.dev/schemas/wheelie/better-than-found-receipt.schema.json",
  "title": "Wheelie better-than-found encountered-issue receipt",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "receiptID",
    "generatedAt",
    "finding",
    "encounter",
    "scope",
    "action",
    "evidenceRefs",
    "noBusywork"
  ],
  "properties": {
    "schemaVersion": {
      "const": "wheelie_better_than_found_receipt/v1"
    },
    "receiptID": {
      "type": "string",
      "minLength": 1
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "finding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["finding", "check", "target"],
      "properties": {
        "finding": {
          "type": "string",
          "minLength": 1
        },
        "check": {
          "type": "string",
          "minLength": 1
        },
        "target": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "encounter": {
      "type": "object",
      "additionalProperties": false,
      "required": ["concreteIssueExists", "sourceSurface"],
      "properties": {
        "concreteIssueExists": {
          "type": "boolean"
        },
        "sourceSurface": {
          "enum": ["agent", "validation", "submit", "handoff", "human_report", "not_applicable"]
        }
      }
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["inCurrentScope", "rationale"],
      "properties": {
        "inCurrentScope": {
          "type": "boolean"
        },
        "rationale": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "action": {
      "type": "object",
      "additionalProperties": false,
      "required": ["actionClass", "actionTaken", "proposedNextAction"],
      "properties": {
        "actionClass": {
          "enum": [
            "simple_fixable_fixed",
            "followup_created",
            "proposal_needed",
            "accepted_not_applicable",
            "blocked_requires_owner"
          ]
        },
        "actionTaken": {
          "type": ["string", "null"]
        },
        "proposedNextAction": {
          "type": ["string", "null"]
        }
      }
    },
    "evidenceRefs": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["kind", "ref"],
        "properties": {
          "kind": {
            "enum": [
              "validation",
              "change",
              "work_item",
              "checkpoint",
              "handoff",
              "policy",
              "source",
              "owner",
              "not_applicable"
            ]
          },
          "ref": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "noBusywork": {
      "type": "object",
      "additionalProperties": false,
      "required": ["concreteEncounterRequired", "arbitraryImprovementSearchPerformed"],
      "properties": {
        "concreteEncounterRequired": {
          "const": true
        },
        "arbitraryImprovementSearchPerformed": {
          "const": false
        }
      }
    }
  }
}
