{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Schema for Location",
  "type": "object",
  "required": ["$schema", "pid", "name", "opening_weekdays"],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "pid": {
      "type": "string",
      "title": "The persistent identifier of this Location"
    },
    "legacy_id": {
      "type": "string",
      "title": "The legacy id of this Location before data migration"
    },
    "name": {
      "type": "string",
      "title": "The name of this Location"
    },
    "address": {
      "type": "string",
      "title": "The address of this Location"
    },
    "email": {
      "type": "string",
      "title": "A contact email"
    },
    "phone": {
      "type": "string",
      "title": "A contact phone"
    },
    "notes": {
      "type": "string",
      "title": "Extra notes"
    },
    "opening_weekdays": {
      "title": "Opening days",
      "description": "Weekly opening schedule",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["weekday", "is_open"],
        "properties": {
          "weekday": {
            "title": "Weekday",
            "type": "string"
          },
          "is_open": {
            "title": "Is open",
            "type": "boolean",
            "default": true
          },
          "times": {
            "title": "Opening times",
            "type": "array",
            "items": {
              "type": "object",
              "required": ["start_time", "end_time"],
              "properties": {
                "start_time": {
                  "title": "Start time",
                  "type": "string"
                },
                "end_time": {
                  "title": "End time",
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "default": [
        {
          "weekday": "monday",
          "is_open": true
        },
        {
          "weekday": "tuesday",
          "is_open": true
        },
        {
          "weekday": "wednesday",
          "is_open": true
        },
        {
          "weekday": "thursday",
          "is_open": true
        },
        {
          "weekday": "friday",
          "is_open": true
        },
        {
          "weekday": "saturday",
          "is_open": false
        },
        {
          "weekday": "sunday",
          "is_open": false
        }
      ]
    },
    "opening_exceptions": {
      "title": "Opening exceptions",
      "description": "Exceptional openings or closures with respect to the weekly schedule",
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "title",
          "is_open",
          "start_date",
          "end_date"
        ],
        "properties": {
          "title": {
            "title": "Title",
            "type": "string"
          },
          "is_open": {
            "title": "Is open",
            "type": "boolean",
            "default": false
          },
          "start_date": {
            "title": "Start date",
            "type": "string",
            "format": "date"
          },
          "end_date": {
            "title": "End date",
            "type": "string",
            "format": "date"
          }
        }
      },
      "default": []
    }
  }
}
