{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "gno://schemas/mcp-job-status@1.0",
  "title": "GNO MCP Job Status",
  "description": "Result payload for gno_job_status",
  "type": "object",
  "required": ["jobId", "type", "status", "startedAt", "serverInstanceId"],
  "$defs": {
    "collectionSyncResult": {
      "type": "object",
      "required": [
        "collection",
        "filesProcessed",
        "filesAdded",
        "filesUpdated",
        "filesUnchanged",
        "filesErrored",
        "filesSkipped",
        "filesMarkedInactive",
        "durationMs",
        "errors"
      ],
      "properties": {
        "collection": {
          "type": "string",
          "description": "Collection name"
        },
        "filesProcessed": {
          "type": "integer",
          "minimum": 0
        },
        "filesAdded": {
          "type": "integer",
          "minimum": 0
        },
        "filesUpdated": {
          "type": "integer",
          "minimum": 0
        },
        "filesUnchanged": {
          "type": "integer",
          "minimum": 0
        },
        "filesErrored": {
          "type": "integer",
          "minimum": 0
        },
        "filesSkipped": {
          "type": "integer",
          "minimum": 0
        },
        "filesMarkedInactive": {
          "type": "integer",
          "minimum": 0
        },
        "durationMs": {
          "type": "integer",
          "minimum": 0
        },
        "errors": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["relPath", "code", "message"],
            "properties": {
              "relPath": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/fileSyncResult"
          }
        }
      }
    },
    "fileSyncResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["relPath", "status"],
      "properties": {
        "relPath": { "type": "string" },
        "status": {
          "enum": ["added", "updated", "unchanged", "error", "skipped"],
          "description": "skipped is used for eligibility refusals (e.g. cloud placeholders, dataless directories) and other non-error skips; error is for fail-closed and I/O failures"
        },
        "docid": { "type": "string" },
        "mirrorHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "contentType": { "type": "string" },
        "contentTypeSource": {
          "enum": ["frontmatter-type", "prefix", "path-ext", "fallback"]
        },
        "errorCode": {
          "type": "string",
          "description": "Machine code for skipped/error outcomes. Source-availability codes include CLOUD_PLACEHOLDER, CLOUD_PARTIAL, DATALESS_DIRECTORY (status=skipped), and SOURCE_AVAILABILITY_UNSUPPORTED, SOURCE_AVAILABILITY_POLICY_FAILED, SOURCE_AVAILABILITY_UNKNOWN, PERMISSION, NOT_FOUND, NOT_FILE, IO_ERROR (fail-closed; unproven prefixes preserve indexed descendants). Distinct from collection egressPolicy."
        },
        "errorMessage": { "type": "string" },
        "recordImport": {
          "$ref": "gno://schemas/record-import@1.0"
        }
      }
    },
    "syncResult": {
      "type": "object",
      "required": [
        "collections",
        "totalDurationMs",
        "totalFilesProcessed",
        "totalFilesAdded",
        "totalFilesUpdated",
        "totalFilesErrored",
        "totalFilesSkipped"
      ],
      "properties": {
        "collections": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/collectionSyncResult"
          }
        },
        "totalDurationMs": {
          "type": "integer",
          "minimum": 0
        },
        "totalFilesProcessed": {
          "type": "integer",
          "minimum": 0
        },
        "totalFilesAdded": {
          "type": "integer",
          "minimum": 0
        },
        "totalFilesUpdated": {
          "type": "integer",
          "minimum": 0
        },
        "totalFilesErrored": {
          "type": "integer",
          "minimum": 0
        },
        "totalFilesSkipped": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "embedResult": {
      "type": "object",
      "required": ["embedded", "errors"],
      "properties": {
        "embedded": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of chunks embedded"
        },
        "errors": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of chunks that failed"
        }
      }
    },
    "indexResult": {
      "type": "object",
      "required": ["sync", "embed"],
      "properties": {
        "sync": {
          "$ref": "#/$defs/syncResult"
        },
        "embed": {
          "$ref": "#/$defs/embedResult"
        }
      }
    },
    "typedResult": {
      "oneOf": [
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "sync" },
            "value": { "$ref": "#/$defs/syncResult" }
          }
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "embed" },
            "value": { "$ref": "#/$defs/embedResult" }
          }
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "index" },
            "value": { "$ref": "#/$defs/indexResult" }
          }
        }
      ]
    }
  },
  "properties": {
    "jobId": {
      "type": "string",
      "description": "Job identifier"
    },
    "type": {
      "type": "string",
      "description": "Job type",
      "enum": ["add", "sync", "embed", "index"]
    },
    "status": {
      "type": "string",
      "description": "Job status",
      "enum": ["running", "completed", "failed"]
    },
    "startedAt": {
      "type": "string",
      "description": "Start time",
      "format": "date-time"
    },
    "completedAt": {
      "type": "string",
      "description": "Completion time",
      "format": "date-time"
    },
    "result": {
      "description": "Legacy sync result (deprecated, use typedResult)",
      "$ref": "#/$defs/syncResult"
    },
    "typedResult": {
      "description": "Typed job result (discriminated union)",
      "$ref": "#/$defs/typedResult"
    },
    "error": {
      "type": "string",
      "description": "Error message if failed"
    },
    "serverInstanceId": {
      "type": "string",
      "description": "Server instance UUID",
      "format": "uuid"
    }
  }
}
