{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://oms.local/schemas/goal-payload.schema.json",
  "title": "OMS canonical goal payload",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "goal_id",
    "objective",
    "repository_scope",
    "queue_scope",
    "stopping_condition",
    "runtime_horizon",
    "budget_profile",
    "policy_profile",
    "creation_nonce",
    "created_at",
    "updated_at",
    "native_snapshot",
    "team_checkpoint",
    "ultragoal_checkpoint",
    "regression_request",
    "park_reason"
  ],
  "properties": {
    "goal_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
    "objective": { "type": "string", "minLength": 1, "maxLength": 32768 },
    "repository_scope": { "type": "string", "pattern": "^/", "maxLength": 4096 },
    "queue_scope": { "type": "string", "minLength": 1, "maxLength": 4096 },
    "stopping_condition": { "type": "string", "minLength": 1, "maxLength": 32768 },
    "runtime_horizon": { "enum": ["until-empty", "12h", "24h"] },
    "budget_profile": { "const": "subscription-only" },
    "policy_profile": { "const": "default" },
    "creation_nonce": {
      "type": "string",
      "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$"
    },
    "created_at": { "type": "string", "minLength": 20, "maxLength": 24 },
    "updated_at": { "type": "string", "minLength": 20, "maxLength": 24 },
    "native_snapshot": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["kind", "artifact_id", "sha256", "file_name"],
      "properties": {
        "kind": { "const": "native-goal-snapshot" },
        "artifact_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "file_name": { "type": "string", "maxLength": 96 }
      }
    },
    "team_checkpoint": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["kind", "artifact_id", "sha256", "file_name"],
      "properties": {
        "kind": { "const": "team-checkpoint" },
        "artifact_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "file_name": { "type": "string", "maxLength": 96 }
      }
    },
    "ultragoal_checkpoint": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["kind", "artifact_id", "sha256", "file_name"],
      "properties": {
        "kind": { "const": "ultragoal-checkpoint" },
        "artifact_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "file_name": { "type": "string", "maxLength": 96 }
      }
    },
    "regression_request": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["kind", "artifact_id", "sha256", "file_name"],
      "properties": {
        "kind": { "const": "regression-request" },
        "artifact_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "file_name": { "type": "string", "maxLength": 96 }
      }
    },
    "park_reason": {
      "type": ["string", "null"],
      "enum": [
        "native-goal-mismatch",
        "stale-native-snapshot",
        "predicate-failed",
        "ultragoal-mismatch",
        null
      ]
    }
  }
}
