{
  "$defs": {
    "Capacity": {
      "additionalProperties": false,
      "properties": {
        "maximum": {
          "$ref": "#/$defs/Sourced_int_",
          "description": "Maximum participant cap (a limit, not a count)."
        },
        "registered": {
          "$ref": "#/$defs/Sourced_int_",
          "description": "Current registrations, only if the source states it."
        },
        "remaining": {
          "$ref": "#/$defs/Sourced_int_",
          "description": "Remaining slots, only if the source states it."
        },
        "waitlist": {
          "$ref": "#/$defs/Sourced_bool_",
          "description": "Whether a waitlist is available/active, only if stated."
        }
      },
      "required": [
        "maximum",
        "registered",
        "remaining",
        "waitlist"
      ],
      "title": "Capacity",
      "type": "object"
    },
    "Countdown": {
      "additionalProperties": false,
      "properties": {
        "field": {
          "title": "Field",
          "type": "string"
        },
        "raw": {
          "description": "Original relative value, kept verbatim.",
          "title": "Raw",
          "type": "string"
        },
        "resolved_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Calendar date-time computed from retrieved_at.",
          "title": "Resolved At"
        },
        "basis": {
          "default": "retrieved_at + relative offset",
          "title": "Basis",
          "type": "string"
        }
      },
      "required": [
        "field",
        "raw",
        "resolved_at"
      ],
      "title": "Countdown",
      "type": "object"
    },
    "DataQuality": {
      "additionalProperties": false,
      "properties": {
        "status": {
          "enum": [
            "ok",
            "partial",
            "error"
          ],
          "title": "Status",
          "type": "string"
        },
        "issues": {
          "items": {
            "$ref": "#/$defs/QualityIssue"
          },
          "title": "Issues",
          "type": "array"
        }
      },
      "required": [
        "status"
      ],
      "title": "DataQuality",
      "type": "object"
    },
    "Distance": {
      "additionalProperties": false,
      "properties": {
        "raw": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Original provider text, e.g. '13.1 Miles'.",
          "title": "Raw"
        },
        "value": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Value"
        },
        "unit": {
          "anyOf": [
            {
              "enum": [
                "m",
                "km",
                "mi",
                "yd"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Unit"
        },
        "meters": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Meters"
        },
        "basis": {
          "default": "none",
          "enum": [
            "provider_distance_field",
            "provider_name_text",
            "none"
          ],
          "title": "Basis",
          "type": "string"
        }
      },
      "required": [
        "raw"
      ],
      "title": "Distance",
      "type": "object"
    },
    "EventInfo": {
      "additionalProperties": false,
      "properties": {
        "event_uid": {
          "title": "Event Uid",
          "type": "string"
        },
        "name": {
          "title": "Name",
          "type": "string"
        },
        "url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Official event / registration page on the provider.",
          "title": "Url"
        },
        "external_url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Organizer's own website, when provided.",
          "title": "External Url"
        },
        "logo_url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Logo Url"
        },
        "timezone": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Timezone"
        },
        "location": {
          "$ref": "#/$defs/Location"
        },
        "next_date": {
          "anyOf": [
            {
              "format": "date",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Next Date"
        },
        "source_registration_open": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Provider's own event-level registration-open flag, verbatim.",
          "title": "Source Registration Open"
        },
        "cancellation_note": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Cancellation Note"
        },
        "source_modified_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Source Modified At"
        }
      },
      "required": [
        "event_uid",
        "name",
        "location"
      ],
      "title": "EventInfo",
      "type": "object"
    },
    "Location": {
      "additionalProperties": false,
      "properties": {
        "venue": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Venue"
        },
        "street": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Street"
        },
        "city": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "City"
        },
        "region": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "State / province code.",
          "title": "Region"
        },
        "postal_code": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Postal Code"
        },
        "country_code": {
          "anyOf": [
            {
              "maxLength": 2,
              "minLength": 2,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Country Code"
        },
        "latitude": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Latitude"
        },
        "longitude": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Longitude"
        }
      },
      "title": "Location",
      "type": "object"
    },
    "Money": {
      "additionalProperties": false,
      "properties": {
        "amount_cents": {
          "minimum": 0,
          "title": "Amount Cents",
          "type": "integer"
        },
        "currency": {
          "anyOf": [
            {
              "maxLength": 3,
              "minLength": 3,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Currency"
        },
        "display": {
          "description": "Original provider text, e.g. '$40.00'.",
          "title": "Display",
          "type": "string"
        }
      },
      "required": [
        "amount_cents",
        "display"
      ],
      "title": "Money",
      "type": "object"
    },
    "Pricing": {
      "additionalProperties": false,
      "properties": {
        "current": {
          "$ref": "#/$defs/Sourced_Money_"
        },
        "current_processing_fee": {
          "anyOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "current_period_ends_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Current Period Ends At"
        },
        "next_price": {
          "anyOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "next_price_change_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Next Price Change At"
        }
      },
      "required": [
        "current"
      ],
      "title": "Pricing",
      "type": "object"
    },
    "QualityIssue": {
      "additionalProperties": false,
      "properties": {
        "code": {
          "title": "Code",
          "type": "string"
        },
        "severity": {
          "default": "warning",
          "enum": [
            "info",
            "warning",
            "error"
          ],
          "title": "Severity",
          "type": "string"
        },
        "field": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Field"
        },
        "message": {
          "title": "Message",
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "title": "QualityIssue",
      "type": "object"
    },
    "Registration": {
      "additionalProperties": false,
      "properties": {
        "url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Url"
        },
        "status": {
          "enum": [
            "open",
            "not_yet_open",
            "closed",
            "full",
            "expired",
            "cancelled",
            "unknown"
          ],
          "title": "Status",
          "type": "string"
        },
        "status_basis": {
          "description": "How the status was determined, e.g. 'provider_sales_status' or 'registration_periods_vs_retrieval_time'.",
          "title": "Status Basis",
          "type": "string"
        },
        "status_reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Status Reason"
        },
        "opens_at": {
          "$ref": "#/$defs/Sourced_datetime_"
        },
        "closes_at": {
          "$ref": "#/$defs/Sourced_datetime_"
        },
        "periods": {
          "items": {
            "$ref": "#/$defs/RegistrationPeriod"
          },
          "title": "Periods",
          "type": "array"
        }
      },
      "required": [
        "url",
        "status",
        "status_basis",
        "opens_at",
        "closes_at"
      ],
      "title": "Registration",
      "type": "object"
    },
    "RegistrationPeriod": {
      "additionalProperties": false,
      "properties": {
        "opens_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Opens At"
        },
        "closes_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Closes At"
        },
        "price": {
          "anyOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "processing_fee": {
          "anyOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "is_current": {
          "default": false,
          "title": "Is Current",
          "type": "boolean"
        }
      },
      "title": "RegistrationPeriod",
      "type": "object"
    },
    "SourceInfo": {
      "additionalProperties": false,
      "properties": {
        "provider": {
          "enum": [
            "runsignup",
            "active",
            "raceroster"
          ],
          "title": "Provider",
          "type": "string"
        },
        "provider_event_id": {
          "title": "Provider Event Id",
          "type": "string"
        },
        "provider_sub_event_id": {
          "title": "Provider Sub Event Id",
          "type": "string"
        },
        "endpoint": {
          "description": "Documented endpoint the record came from (no credentials).",
          "title": "Endpoint",
          "type": "string"
        },
        "documentation_url": {
          "title": "Documentation Url",
          "type": "string"
        },
        "retrieved_at": {
          "format": "date-time",
          "title": "Retrieved At",
          "type": "string"
        },
        "run_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Run Id"
        }
      },
      "required": [
        "provider",
        "provider_event_id",
        "provider_sub_event_id",
        "endpoint",
        "documentation_url",
        "retrieved_at"
      ],
      "title": "SourceInfo",
      "type": "object"
    },
    "Sourced_Money_": {
      "additionalProperties": false,
      "properties": {
        "value": {
          "anyOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "availability": {
          "enum": [
            "available",
            "not_provided",
            "unavailable_at_source",
            "not_retrieved",
            "restricted"
          ],
          "title": "Availability",
          "type": "string"
        },
        "source_field": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Exact provider field the value came from.",
          "title": "Source Field"
        },
        "note": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Note"
        }
      },
      "required": [
        "availability"
      ],
      "title": "Sourced[Money]",
      "type": "object"
    },
    "Sourced_bool_": {
      "additionalProperties": false,
      "properties": {
        "value": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Value"
        },
        "availability": {
          "enum": [
            "available",
            "not_provided",
            "unavailable_at_source",
            "not_retrieved",
            "restricted"
          ],
          "title": "Availability",
          "type": "string"
        },
        "source_field": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Exact provider field the value came from.",
          "title": "Source Field"
        },
        "note": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Note"
        }
      },
      "required": [
        "availability"
      ],
      "title": "Sourced[bool]",
      "type": "object"
    },
    "Sourced_datetime_": {
      "additionalProperties": false,
      "properties": {
        "value": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Value"
        },
        "availability": {
          "enum": [
            "available",
            "not_provided",
            "unavailable_at_source",
            "not_retrieved",
            "restricted"
          ],
          "title": "Availability",
          "type": "string"
        },
        "source_field": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Exact provider field the value came from.",
          "title": "Source Field"
        },
        "note": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Note"
        }
      },
      "required": [
        "availability"
      ],
      "title": "Sourced[datetime]",
      "type": "object"
    },
    "Sourced_int_": {
      "additionalProperties": false,
      "properties": {
        "value": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Value"
        },
        "availability": {
          "enum": [
            "available",
            "not_provided",
            "unavailable_at_source",
            "not_retrieved",
            "restricted"
          ],
          "title": "Availability",
          "type": "string"
        },
        "source_field": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Exact provider field the value came from.",
          "title": "Source Field"
        },
        "note": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Note"
        }
      },
      "required": [
        "availability"
      ],
      "title": "Sourced[int]",
      "type": "object"
    },
    "SubEventInfo": {
      "additionalProperties": false,
      "properties": {
        "name": {
          "title": "Name",
          "type": "string"
        },
        "event_type": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Event Type"
        },
        "distance": {
          "$ref": "#/$defs/Distance"
        },
        "start_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Start At"
        },
        "end_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "End At"
        },
        "start_local": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Start as shown by the provider, in the event's timezone.",
          "title": "Start Local"
        },
        "event_date": {
          "anyOf": [
            {
              "format": "date",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Event Date"
        }
      },
      "required": [
        "name",
        "distance"
      ],
      "title": "SubEventInfo",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "A single directory record: one sub-event / distance of one event.",
  "properties": {
    "schema_version": {
      "const": "1.0.0",
      "default": "1.0.0",
      "title": "Schema Version",
      "type": "string"
    },
    "record_id": {
      "pattern": "^(runsignup|active|raceroster):[^:]+:[^:]+$",
      "title": "Record Id",
      "type": "string"
    },
    "source": {
      "$ref": "#/$defs/SourceInfo"
    },
    "event": {
      "$ref": "#/$defs/EventInfo"
    },
    "sub_event": {
      "$ref": "#/$defs/SubEventInfo"
    },
    "registration": {
      "$ref": "#/$defs/Registration"
    },
    "pricing": {
      "$ref": "#/$defs/Pricing"
    },
    "capacity": {
      "$ref": "#/$defs/Capacity"
    },
    "countdowns": {
      "items": {
        "$ref": "#/$defs/Countdown"
      },
      "title": "Countdowns",
      "type": "array"
    },
    "data_quality": {
      "$ref": "#/$defs/DataQuality"
    },
    "content_hash": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "SHA-256 of the record's material fields.",
      "title": "Content Hash"
    }
  },
  "required": [
    "record_id",
    "source",
    "event",
    "sub_event",
    "registration",
    "pricing",
    "capacity",
    "data_quality"
  ],
  "title": "EventRecord",
  "type": "object",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://endurance-event-hub.pages.dev/schema/event-record.schema.json"
}