{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:tmpa:schema:lifecycle-profile:s1.0",
  "title": "TMPA Lifecycle Profile S1.0",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "version", "states", "initial_state", "terminal_states", "actions", "transitions", "acceptance", "work_graph", "risk_policy", "failure_model"],
  "properties": {
    "id": { "type": "string", "minLength": 1 },
    "version": { "type": "string", "minLength": 1 },
    "states": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
    "initial_state": { "type": "string", "minLength": 1 },
    "terminal_states": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
    "actions": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
    "transitions": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["from", "action", "to", "allowed_roles", "required_relations"],
        "properties": {
          "from": { "type": "string", "minLength": 1 },
          "action": { "type": "string", "minLength": 1 },
          "to": { "type": "string", "minLength": 1 },
          "allowed_roles": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
          "required_relations": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
          "preconditions": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
          "separation_of_duties": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
        }
      }
    },
    "recovery_rules": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
    "acceptance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["states_requiring_acceptance", "acceptance_relations", "allowed_roles", "requires_independent_actor", "archive_requires_acceptance"],
      "properties": {
        "states_requiring_acceptance": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "acceptance_relations": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "allowed_roles": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "requires_independent_actor": { "type": "boolean" },
        "archive_requires_acceptance": { "type": "boolean" }
      }
    },
    "work_graph": {
      "type": "object",
      "additionalProperties": false,
      "required": ["completion_claim_predicates", "response_relations", "child_terminal_states"],
      "properties": {
        "completion_claim_predicates": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "response_relations": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "child_terminal_states": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
      }
    },
    "risk_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["human_approval_levels", "approval_relations", "approval_roles", "approval_object_types", "requires_independent_actor"],
      "properties": {
        "human_approval_levels": { "type": "array", "uniqueItems": true, "items": { "enum": ["low", "medium", "high", "irreversible"] } },
        "approval_relations": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "approval_roles": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "approval_object_types": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "requires_independent_actor": { "type": "boolean" }
      }
    },
    "failure_model": {
      "type": "object",
      "additionalProperties": false,
      "required": ["failure_types", "recovery_actions"],
      "properties": {
        "failure_types": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "recovery_actions": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
      }
    },
    "extensions": { "type": "object", "additionalProperties": true }
  }
}
