{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/scrip-dev/json-schema/scrip-dev-event-impact-response-schema.json",
  "title": "EventImpactResponse",
  "description": "An event with everything it caused: rule evaluations, journal entries, balance changes and state changes.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/scrip-dev-openapi.json#/components/schemas/EventImpactResponse",
  "properties": {
    "balance_impact": {
      "description": "Net balance impact per entity/asset/bucket",
      "items": {
        "$ref": "#/$defs/BalanceImpactResponse"
      },
      "type": "array"
    },
    "created_at": {
      "description": "When this event was created",
      "format": "date-time",
      "type": "string"
    },
    "error_code": {
      "description": "Why a FAILED event failed, as a code from the Errors page, such as `program_inactive`, `participant_inactive` or `unknown_participant`. Absent when the event did not fail or the failure has no code.",
      "type": "string"
    },
    "error_message": {
      "description": "Error details if the event failed during processing",
      "type": "string"
    },
    "event_data": {
      "description": "Original event data payload",
      "type": "object"
    },
    "event_timestamp": {
      "description": "When the event occurred (from the ingestion request)",
      "format": "date-time",
      "type": "string"
    },
    "event_type": {
      "description": "The name you gave the event, such as `purchase`. Rules read it as `event.type`. Absent for an event stored before events had a name.",
      "type": "string"
    },
    "external_id": {
      "description": "Your system's identifier for the participant (the value provided at ingestion)",
      "type": "string"
    },
    "first_error_code": {
      "description": "The event's cause: the first error_code it failed with. GET /v1/reports/failure-causes groups events by it, and GET /v1/events can filter by it. The event keeps it after a retry. Absent when the event never failed with a code.",
      "type": "string"
    },
    "first_failed_at": {
      "description": "When the event first failed (RFC 3339). The event keeps it after a retry; its latest failure is processed_at. Absent when the event never failed.",
      "format": "date-time",
      "type": "string"
    },
    "id": {
      "description": "Unique identifier for this event",
      "format": "uuid",
      "type": "string"
    },
    "idempotency_key": {
      "description": "Client-provided unique key for deduplication",
      "type": "string"
    },
    "journal_entries": {
      "description": "Journal entries created by this event with their double-entry postings",
      "items": {
        "$ref": "#/$defs/JournalEntryResponse"
      },
      "type": "array"
    },
    "participant_id": {
      "description": "Participant UUID, resolved from external_id if one was provided at ingestion",
      "format": "uuid",
      "type": "string"
    },
    "processed_at": {
      "description": "When the event finished processing (null while pending or processing)",
      "format": "date-time",
      "type": "string"
    },
    "program_id": {
      "description": "Program this event belongs to",
      "format": "uuid",
      "type": "string"
    },
    "received_at": {
      "description": "When Scrip received the event",
      "format": "date-time",
      "type": "string"
    },
    "recipient_id": {
      "description": "Recipient participant UUID sent as recipient_id or recipient_external_id; rules read it as recipient.id",
      "format": "uuid",
      "type": "string"
    },
    "reversal": {
      "$ref": "#/$defs/EventReversalSummary",
      "description": "Whether the rewards this event issued were later reversed."
    },
    "rule_evaluations": {
      "description": "Recorded rule-evaluation rows for this event. Rules whose conditions cleanly evaluate to false are not recorded; later rules in the same set after a successful stop_after_match are not evaluated or recorded.",
      "items": {
        "$ref": "#/$defs/RuleEvaluationResponse"
      },
      "type": "array"
    },
    "source": {
      "description": "Whether you sent the event or Scrip generated it.",
      "enum": [
        "EXTERNAL",
        "SYSTEM",
        "OPERATIONAL"
      ],
      "type": "string"
    },
    "state_changes": {
      "description": "State changes (tags, counters, attributes, tiers) caused by this event",
      "items": {
        "$ref": "#/$defs/StateChangeResponse"
      },
      "type": "array"
    },
    "status": {
      "description": "Where the event is in processing.",
      "enum": [
        "PENDING",
        "PROCESSING",
        "COMPLETED",
        "FAILED"
      ],
      "type": "string"
    },
    "updated_at": {
      "description": "When this event was last updated",
      "format": "date-time",
      "type": "string"
    }
  },
  "type": "object",
  "$defs": {
    "BalanceImpactResponse": {
      "description": "The net balance change an event caused for one participant, group or program wallet in one asset.",
      "properties": {
        "amount": {
          "description": "Net amount change (positive = credit, negative = debit)",
          "type": "string"
        },
        "asset_symbol": {
          "description": "Asset being affected",
          "type": "string"
        },
        "bucket": {
          "description": "The balance bucket the change affected.",
          "enum": [
            "AVAILABLE",
            "HELD",
            "DEFERRED"
          ],
          "type": "string"
        },
        "entity_id": {
          "description": "Public UUID of the entity (null for SYSTEM_* types)",
          "format": "uuid",
          "type": "string"
        },
        "entity_type": {
          "description": "The kind of account the change posted to.",
          "enum": [
            "PARTICIPANT",
            "GROUP",
            "PROGRAM",
            "PROGRAM_TEST",
            "SYSTEM_ISSUANCE",
            "SYSTEM_BREAKAGE",
            "SYSTEM_REDEMPTION"
          ],
          "type": "string"
        }
      },
      "type": "object"
    },
    "CounterPeriod": {
      "description": "The calendar period changed by this history entry. Its start is inclusive and its end is exclusive; both are UTC timestamps.",
      "properties": {
        "end": {
          "description": "First instant of the following period, in UTC (exclusive).",
          "type": "string"
        },
        "period_new_value": {
          "description": "The changed period's own total after this change. Present only with `window_count`. `new_value` is the window total.",
          "type": "string"
        },
        "period_old_value": {
          "description": "The changed period's own total before this change. Present only with `window_count`. `old_value` is the window total.",
          "type": "string"
        },
        "start": {
          "description": "First instant of the period, in UTC (inclusive).",
          "type": "string"
        },
        "timezone": {
          "description": "IANA time zone used to calculate the period boundaries.",
          "type": "string"
        },
        "type": {
          "description": "Calendar period: DAY, WEEK or MONTH.",
          "enum": [
            "DAY",
            "WEEK",
            "MONTH"
          ],
          "type": "string"
        },
        "window_count": {
          "description": "Periods the counter's window adds up. Present only for a counter whose state definition declares a `window`.",
          "type": "integer"
        }
      },
      "required": [
        "type"
      ],
      "type": "object"
    },
    "EventReversalSummary": {
      "description": "Whether the rewards an event issued were reversed, and when. Read each reversal with GET /v1/events/{event_id}?expand[]=reversals.",
      "properties": {
        "last_reversed_at": {
          "description": "When the latest reversal was made (RFC 3339). Absent when status is NONE.",
          "format": "date-time",
          "type": "string"
        },
        "status": {
          "description": "Reversal state: `NONE` (not reversed), `PARTIAL` (partially reversed), or `FULL` (all reversible awards recovered).",
          "enum": [
            "NONE",
            "PARTIAL",
            "FULL"
          ],
          "type": "string"
        }
      },
      "type": "object"
    },
    "JournalEntryResponse": {
      "description": "A journal entry with its metadata and double-entry postings",
      "properties": {
        "action_type": {
          "description": "The kind of ledger action the entry records. A manual adjustment is a `CREDIT` or `DEBIT`; no operation creates `ADJUSTMENT` entries.",
          "enum": [
            "CREDIT",
            "DEBIT",
            "TRANSFER",
            "HOLD",
            "RELEASE",
            "FORFEIT",
            "EXPIRATION",
            "REDEMPTION",
            "REVERSAL",
            "BURN",
            "FUND",
            "ADJUSTMENT",
            "MATURITY",
            "VOID_PENDING"
          ],
          "type": "string"
        },
        "created_at": {
          "description": "When this entry was created (RFC 3339)",
          "format": "date-time",
          "type": "string"
        },
        "description": {
          "description": "Human-readable explanation of the entry's purpose",
          "type": "string"
        },
        "entry_hash": {
          "description": "SHA-256 hash sealing this entry into the organization's hash chain",
          "type": "string"
        },
        "event_id": {
          "description": "Event that triggered this entry (null if created via direct API call)",
          "format": "uuid",
          "type": "string"
        },
        "id": {
          "description": "Unique identifier for this journal entry",
          "format": "uuid",
          "type": "string"
        },
        "postings": {
          "description": "Double-entry postings. They always sum to zero.",
          "items": {
            "$ref": "#/$defs/PostingResponse"
          },
          "type": "array"
        },
        "program_id": {
          "description": "Program this entry belongs to",
          "format": "uuid",
          "type": "string"
        },
        "program_name": {
          "description": "The name of the program the entry ran under.",
          "type": "string"
        },
        "reference_id": {
          "description": "Correlation ID linking holds to releases",
          "type": "string"
        },
        "rule_id": {
          "description": "Rule that triggered this entry. It is null for direct API calls and for entries Scrip creates itself.",
          "format": "uuid",
          "type": "string"
        }
      },
      "type": "object"
    },
    "PostingResponse": {
      "description": "A single line in a journal entry representing one side of a double-entry transaction",
      "properties": {
        "amount": {
          "description": "Posting amount (positive = credit, negative = debit)",
          "type": "string"
        },
        "asset_symbol": {
          "description": "Asset being transacted",
          "type": "string"
        },
        "bucket": {
          "description": "The balance bucket the posting affects.",
          "enum": [
            "AVAILABLE",
            "HELD",
            "DEFERRED"
          ],
          "type": "string"
        },
        "created_at": {
          "description": "When this posting was created (RFC 3339)",
          "format": "date-time",
          "type": "string"
        },
        "entity_type": {
          "description": "The kind of account the posting belongs to.",
          "enum": [
            "PARTICIPANT",
            "GROUP",
            "PROGRAM",
            "PROGRAM_TEST",
            "SYSTEM_ISSUANCE",
            "SYSTEM_BREAKAGE",
            "SYSTEM_REDEMPTION"
          ],
          "type": "string"
        },
        "group_id": {
          "description": "Group that owns this account (set when entity_type is GROUP)",
          "format": "uuid",
          "type": "string"
        },
        "id": {
          "description": "Unique identifier for this posting",
          "format": "uuid",
          "type": "string"
        },
        "participant_id": {
          "description": "Participant who owns this account (set when entity_type is PARTICIPANT)",
          "format": "uuid",
          "type": "string"
        },
        "program_id": {
          "description": "Program that owns this account (set when entity_type is PROGRAM)",
          "format": "uuid",
          "type": "string"
        }
      },
      "type": "object"
    },
    "RuleEvaluationResponse": {
      "description": "The outcome of one rule for one event, and why.",
      "properties": {
        "created_at": {
          "description": "When the evaluation occurred",
          "format": "date-time",
          "type": "string"
        },
        "error_message": {
          "description": "Details of a failure or skip (e.g. budget usage and reset time for `PARTICIPANT_BUDGET_EXCEEDED`, or the conflicting key for `SHARED_STATE_CHANGED`).",
          "type": "string"
        },
        "id": {
          "description": "Unique identifier for this evaluation record",
          "format": "uuid",
          "type": "string"
        },
        "reason": {
          "description": "Skip classification for `SKIPPED` evaluations (`OUTSIDE_TIME_WINDOW`, `BUDGET_EXCEEDED`, `PARTICIPANT_BUDGET_EXCEEDED`, or `SHARED_STATE_CHANGED`), or `REFERENCE_ALREADY_SETTLED` on a `SUCCESS` evaluation. Absent otherwise.",
          "type": "string"
        },
        "rule_history_id": {
          "description": "Snapshot of the rule version that was active when this evaluation occurred",
          "format": "uuid",
          "type": "string"
        },
        "rule_id": {
          "description": "Rule that was evaluated",
          "format": "uuid",
          "type": "string"
        },
        "rule_name": {
          "description": "The name of the rule when it was evaluated.",
          "type": "string"
        },
        "rule_set_id": {
          "description": "Rule set that contained the rule when this evaluation occurred",
          "format": "uuid",
          "type": "string"
        },
        "status": {
          "description": "The recorded result of the evaluation.",
          "enum": [
            "SUCCESS",
            "FAILED",
            "SKIPPED",
            "SKIPPED_ERROR",
            "SKIPPED_TIMEOUT"
          ],
          "type": "string"
        },
        "stopped_by_rule_id": {
          "description": "Earlier rule whose `stop_after_match` skipped this rule (present only in rule configuration simulations).",
          "format": "uuid",
          "type": "string"
        }
      },
      "type": "object"
    },
    "StateChangeResponse": {
      "description": "A change an event made to a participant's or group's state, such as a counter, tag or attribute.",
      "properties": {
        "changed_at": {
          "description": "When the change occurred (RFC 3339)",
          "format": "date-time",
          "type": "string"
        },
        "counter_period": {
          "$ref": "#/$defs/CounterPeriod",
          "description": "Calendar period changed by this entry; absent for an ordinary counter."
        },
        "entity_id": {
          "description": "Public UUID of the affected entity",
          "format": "uuid",
          "type": "string"
        },
        "entity_type": {
          "description": "Whose state changed: a participant, a group, or the program.",
          "enum": [
            "PARTICIPANT",
            "GROUP",
            "PROGRAM"
          ],
          "type": "string"
        },
        "key": {
          "description": "The key that changed",
          "type": "string"
        },
        "new_value": {
          "description": "New value (null for deletes)",
          "type": "string"
        },
        "old_value": {
          "description": "Previous value (null for new keys)",
          "type": "string"
        },
        "operation": {
          "description": "What happened to the key: a value was written, the key was removed, or a counter was reset to zero on its schedule.",
          "enum": [
            "SET",
            "DELETE",
            "AUTO_RESET"
          ],
          "type": "string"
        },
        "program_id": {
          "description": "Program scope for tier changes",
          "format": "uuid",
          "type": "string"
        },
        "rule_id": {
          "description": "Rule that caused this change",
          "format": "uuid",
          "type": "string"
        },
        "state_type": {
          "description": "Which kind of state changed.",
          "enum": [
            "TAG",
            "COUNTER",
            "ATTRIBUTE",
            "TIER"
          ],
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}