{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "title": "Library",
    "description": "JSON schema for a library",
    "additionalProperties": false,
    "required": [
        "$schema",
        "code",
        "pid",
        "name",
        "organisation"
    ],
    "properties": {
        "$schema": {
            "title": "Schema",
            "description": "Schema to validate organisation records against.",
            "type": "string",
            "minLength": 9,
            "default": "https://ils.rero.ch/schemas/libraries/library-v0.0.1.json"
        },
        "pid": {
            "title": "Library ID",
            "type": "string"
        },
        "organisation": {
            "title": "Organisation",
            "type": "object",
            "properties": {
                "$ref": {
                    "title": "Organisation URI",
                    "type": "string",
                    "pattern": "^https://ils.rero.ch/api/organisations/.*?$"
                }
            }
        },
        "code": {
            "title": "Code",
            "description": "Code of the library.",
            "type": "string"
        },
        "name": {
            "title": "Name",
            "description": "Name of the library.",
            "type": "string",
            "minLength": 1
        },
        "address": {
            "title": "Address",
            "description": "Address of the library.",
            "type": "string",
            "minLength": 1
        },
        "email": {
            "title": "Email",
            "description": "Email of the library.",
            "type": "string",
            "format": "email",
            "pattern": "^.*?@.*.*$",
            "minLength": 3
        },
        "opening_hours": {
            "title": "Opening Hours",
            "description": "Weekly opening hours",
            "required": [
                "day",
                "is_open",
                "times"
            ],
            "default": [
                {
                    "day": "monday",
                    "is_open": false,
                    "times": [
                        {
                            "start_time": "08:00",
                            "end_time": "17:00"
                        }
                    ]
                },
                {
                    "day": "tuesday",
                    "is_open": false,
                    "times": [
                        {
                            "start_time": "08:00",
                            "end_time": "17:00"
                        }
                    ]
                },
                {
                    "day": "wednesday",
                    "is_open": false,
                    "times": [
                        {
                            "start_time": "08:00",
                            "end_time": "17:00"
                        }
                    ]
                },
                {
                    "day": "thursday",
                    "is_open": false,
                    "times": [
                        {
                            "start_time": "08:00",
                            "end_time": "17:00"
                        }
                    ]
                },
                {
                    "day": "friday",
                    "is_open": false,
                    "times": [
                        {
                            "start_time": "08:00",
                            "end_time": "17:00"
                        }
                    ]
                },
                {
                    "day": "saturday",
                    "is_open": false,
                    "times": [
                        {
                            "start_time": "08:00",
                            "end_time": "17:00"
                        }
                    ]
                },
                {
                    "day": "sunday",
                    "is_open": false,
                    "times": [
                        {
                            "start_time": "08:00",
                            "end_time": "17:00"
                        }
                    ]
                }
            ],
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "day": {
                        "title": "Day",
                        "description": "Weekday.",
                        "type": "string"
                    },
                    "is_open": {
                        "title": "Is open",
                        "type": "boolean",
                        "default": "false"
                    },
                    "times": {
                        "type": "array",
                        "required": [
                            "start_time",
                            "end_time"
                        ],
                        "default": [
                            {
                                "start_time": "08:00",
                                "end_time": "17:00"
                            }
                        ],
                        "items": {
                            "type": "object",
                            "properties": {
                                "start_time": {
                                    "type": "string",
                                    "minLength": 5,
                                    "maxLength": 5,
                                    "default": "08:00"
                                },
                                "end_time": {
                                    "type": "string",
                                    "minLength": 5,
                                    "maxLength": 5,
                                    "default": "17:00"
                                }
                            }
                        }
                    }
                }
            }
        },
        "exception_dates": {
            "title": "Exception Hours",
            "description": "Exception opening hours",
            "type": "array",
            "default": [],
            "items": {
                "type": "object",
                "required": [
                    "title",
                    "is_open",
                    "start_date"
                ],
                "properties": {
                    "title": {
                        "type": "string"
                    },
                    "is_open": {
                        "type": "boolean"
                    },
                    "start_date": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "end_date": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "times": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "start_time": {
                                "type": "string",
                                "format": "date-time"
                            },
                            "end_time": {
                                "type": "string",
                                "format": "date-time"
                            }
                        }
                    },
                    "repeat": {
                        "type": "object",
                        "properties": {
                            "interval": {
                                "type": "integer"
                            },
                            "period": {
                                "type": "string",
                                "enum": [
                                    "daily",
                                    "weekly",
                                    "monthly",
                                    "yearly"
                                ]
                            },
                            "data": {
                                "type": "array",
                                "items": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}