{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://backpr.com/standard/v1/family.schema.json",
  "$comment": "Open Youth Registration format 1.x, BackPR, https://backpr.com/open-youth-registration. CC BY 4.0: https://creativecommons.org/licenses/by/4.0/",
  "title": "Family profile",
  "description": "Everything a family fills in once: guardians, children, health, emergency contacts, pickup rules and consents. Families can keep this file (as an export file with one family and no programs) and share it with programs that accept the format. Custom fields must start with x- (for example x-bunk); other names are reserved for this format. Software that rewrites a file must keep fields it doesn't recognize.",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "common.schema.json#/$defs/id"
    },
    "guardians": {
      "type": "array",
      "items": {
        "$ref": "guardian.schema.json"
      },
      "minItems": 1
    },
    "participants": {
      "type": "array",
      "items": {
        "$ref": "participant.schema.json"
      },
      "minItems": 1
    },
    "emergencyContacts": {
      "type": "array",
      "items": {
        "$ref": "contact.schema.json"
      },
      "description": "Listed in the order staff should call them (or by priority)."
    },
    "authorizedPickup": {
      "type": "array",
      "items": {
        "$ref": "contact.schema.json"
      },
      "description": "Adults other than guardians who may pick up. Guardians may pick up unless canPickUp is false or a pickup restriction names them."
    },
    "pickupRestrictions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "personId": {
            "type": "string",
            "description": "Id of the guardian or contact this applies to, if listed in this file."
          },
          "description": {
            "type": "string",
            "description": "How to recognize them, or other details."
          },
          "participantIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Children this applies to, by participant id. If absent or empty, it applies to every child in the family."
          },
          "courtOrder": {
            "type": "object",
            "properties": {
              "onFile": {
                "type": "boolean",
                "description": "The program has a copy of the court order."
              },
              "type": {
                "type": "string",
                "description": "For example custody order or protective order."
              },
              "expires": {
                "$ref": "common.schema.json#/$defs/date"
              }
            }
          }
        },
        "required": [
          "name"
        ]
      },
      "description": "People who may NOT pick up. Programs generally can't refuse a parent or legal guardian without a court order."
    },
    "consents": {
      "type": "array",
      "items": {
        "$ref": "consent.schema.json"
      }
    },
    "preferredLanguage": {
      "$ref": "common.schema.json#/$defs/language"
    },
    "externalIds": {
      "$ref": "common.schema.json#/$defs/externalIds"
    },
    "updatedAt": {
      "$ref": "common.schema.json#/$defs/dateTime",
      "description": "When this record last changed. When two files disagree, the later updatedAt wins."
    }
  },
  "required": [
    "id",
    "guardians",
    "participants"
  ],
  "additionalProperties": true
}