{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://teamshift.io/human-api/task-spec/v1/inspection.schema.json",
  "title": "Inspection with a written report",
  "description": "Up to 60 minutes on site, with a structured report and photos.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "task_type",
    "spec_version",
    "risk_tier",
    "inputs",
    "proof"
  ],
  "properties": {
    "task_type": {
      "const": "inspection"
    },
    "spec_version": {
      "const": "1"
    },
    "risk_tier": {
      "enum": [
        "exterior",
        "interior",
        "entry"
      ],
      "default": "exterior"
    },
    "inputs": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "location",
        "checklist"
      ],
      "properties": {
        "location": {
          "$ref": "common.schema.json#/$defs/location"
        },
        "window": {
          "$ref": "common.schema.json#/$defs/window"
        },
        "instructions": {
          "$ref": "common.schema.json#/$defs/instructions"
        },
        "checklist": {
          "type": "array",
          "minItems": 1,
          "maxItems": 30,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "question",
              "answer"
            ],
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,39}$",
                "examples": [
                  "gate_closed"
                ]
              },
              "question": {
                "type": "string",
                "maxLength": 200,
                "examples": [
                  "Is the back gate closed and latched?"
                ]
              },
              "answer": {
                "enum": [
                  "boolean",
                  "number",
                  "text",
                  "choice"
                ]
              },
              "choices": {
                "type": "array",
                "items": {
                  "type": "string",
                  "maxLength": 60
                },
                "maxItems": 10
              }
            }
          }
        },
        "areas": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "maxLength": 80
          },
          "description": "Areas the report must cover.",
          "examples": [
            [
              "Roof",
              "Kitchen"
            ]
          ]
        }
      }
    },
    "proof": {
      "allOf": [
        {
          "$ref": "common.schema.json#/$defs/proof"
        }
      ],
      "default": {
        "shots": 6,
        "geofence_radius_m": 250,
        "capture_window": {
          "not_before": "dispatch"
        },
        "channel": "capture_link"
      }
    },
    "output": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "answers",
        "report"
      ],
      "properties": {
        "answers": {
          "type": "object",
          "maxProperties": 30,
          "description": "One value per checklist id, typed by its answer kind, for example {\"gate_closed\": true}.",
          "propertyNames": {
            "pattern": "^[a-z][a-z0-9_]{0,39}$"
          },
          "additionalProperties": {
            "type": [
              "boolean",
              "number",
              "string"
            ],
            "maxLength": 500
          }
        },
        "report": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "summary",
            "findings"
          ],
          "properties": {
            "summary": {
              "type": "string",
              "maxLength": 2000
            },
            "findings": {
              "type": "array",
              "maxItems": 40,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "area",
                  "condition"
                ],
                "properties": {
                  "area": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "condition": {
                    "enum": [
                      "good",
                      "fair",
                      "poor",
                      "not_accessible"
                    ]
                  },
                  "note": {
                    "$ref": "common.schema.json#/$defs/note"
                  },
                  "photos": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "pattern": "^[0-9a-f]{64}$"
                    },
                    "description": "SHA-256 of the proof photos that show this finding."
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
