{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/Sharathvc23/forgetproof/main/schemas/forget-me/v1/operation.schema.json",
  "title": "ForgetMe v1: Operation",
  "description": "What submit returns and what GET {endpoint}/operations/{id} answers. `outcome` is null until the state is final. A done operation may still improve: a holder row with outcome queued can later report a final outcome under the same id (`outstanding` says how many rows are not final; `updated_at` moves). Servers may add fields; clients ignore what they don't know.",
  "type": "object",
  "properties": {
    "operation": { "$ref": "common.schema.json#/$defs/operation-id" },
    "namespace": { "$ref": "common.schema.json#/$defs/namespace" },
    "version": { "$ref": "common.schema.json#/$defs/version" },
    "state": { "$ref": "common.schema.json#/$defs/state" },
    "terms": { "$ref": "common.schema.json#/$defs/terms" },
    "item": { "$ref": "common.schema.json#/$defs/item" },
    "submitted_at": { "$ref": "common.schema.json#/$defs/date-time" },
    "started_at": { "$ref": "common.schema.json#/$defs/nullable-date-time" },
    "finished_at": { "$ref": "common.schema.json#/$defs/nullable-date-time" },
    "updated_at": { "$ref": "common.schema.json#/$defs/nullable-date-time" },
    "retrieval_stopped_at": { "$ref": "common.schema.json#/$defs/nullable-date-time" },
    "outcome": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "properties": {
            "overall": { "$ref": "common.schema.json#/$defs/outcome" },
            "sentence": { "$ref": "common.schema.json#/$defs/text" },
            "holders": { "type": "array", "maxItems": 64, "items": { "$ref": "common.schema.json#/$defs/holder-row" } },
            "counts": { "type": "object", "additionalProperties": { "type": "integer", "minimum": 0 } },
            "kept": {
              "type": "object",
              "properties": { "memories": { "type": "integer", "minimum": 0 }, "note": { "$ref": "common.schema.json#/$defs/text" } }
            },
            "uncertain": { "type": "boolean" },
            "outstanding": { "type": "integer", "minimum": 0 }
          },
          "required": ["overall", "sentence", "holders"]
        }
      ]
    },
    "log": {
      "type": "array",
      "maxItems": 200,
      "items": {
        "type": "object",
        "properties": {
          "actor": { "type": "string", "maxLength": 64 },
          "text": { "$ref": "common.schema.json#/$defs/text" },
          "at": { "$ref": "common.schema.json#/$defs/date-time" }
        },
        "required": ["actor", "text", "at"]
      }
    },
    "reconciled": { "oneOf": [{ "$ref": "common.schema.json#/$defs/text" }, { "type": "null" }] },
    "status_url": { "type": "string", "minLength": 1, "maxLength": 2048 },
    "evidence_url": { "type": "string", "minLength": 1, "maxLength": 2048 }
  },
  "required": ["operation", "namespace", "version", "state", "terms", "item", "submitted_at", "outcome", "status_url", "evidence_url"],
  "additionalProperties": true,
  "allOf": [
    { "if": { "properties": { "state": { "enum": ["accepted", "running"] } } }, "then": { "properties": { "outcome": { "type": "null" } } } },
    { "if": { "properties": { "state": { "enum": ["done", "error"] } } }, "then": { "properties": { "outcome": { "type": "object" } } } }
  ]
}
