{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "title": "Circulation policy",
    "description": "JSON schema for circulation policies.",
    "additionalProperties": false,
    "required": [
        "$schema",
        "pid",
        "name",
        "organisation",
        "is_default"
    ],
    "properties": {
        "$schema": {
            "title": "Schema",
            "description": "Schema to validate circulation policies records against.",
            "type": "string",
            "minLength": 9,
            "default": "https://ils.rero.ch/schemas/circ_policies/circ_policy-v0.0.1.json"
        },
        "pid": {
            "title": "Circulation policy ID",
            "type": "string",
            "minLength": 1
        },
        "name": {
            "title": "Circulation policy name",
            "description": "The name of the circulation policy.",
            "type": "string",
            "minLength": 2
        },
        "description": {
            "title": "Circulation policy description",
            "description": "The description of the circulation policy.",
            "type": "string"
        },
        "organisation": {
            "title": "Organisation",
            "type": "object",
            "properties": {
                "$ref": {
                    "title": "Organisation URI",
                    "type": "string",
                    "pattern": "^https://ils.rero.ch/api/organisations/.*?$"
                }
            }
        },
        "allow_checkout": {
            "title": "Allow Checkout",
            "description": "Checkouts are allowed or not.",
            "type": "boolean",
            "default": true
        },
        "checkout_duration": {
            "title": "Checkout duration in days",
            "description": "The duration of the checkout in days.",
            "type": "integer",
            "minimum": 1,
            "default": 7
        },
        "allow_requests": {
            "title": "Allow patron requests",
            "description": "Patron requests are allowed or not.",
            "type": "boolean",
            "default": true
        },
        "number_of_days_before_due_date": {
            "title": "Number of days before due date.",
            "description": "Number of days before due date for sending the due_soon notification.",
            "type": "integer",
            "default": 5,
            "minimum": 0
        },
        "number_of_days_after_due_date": {
            "title": "Number of days after due date",
            "description": "Number of days after due date for sending the first overdue notification.",
            "type": "integer",
            "default": 5,
            "minimum": 1
        },
        "reminder_fee_amount": {
            "title": "The amount of reminder fee",
            "description": "Overdue amount.",
            "type": "number",
            "default": 2.0
        },
        "number_renewals": {
            "title": "Maximum number of renewals",
            "description": "Maximum number of renewals allowed.",
            "type": "integer",
            "minimum": 0,
            "default": 0
        },
        "renewal_duration": {
            "title": "Renewal duration in days",
            "description": "The duration of the renewal in days.",
            "type": "integer",
            "minimum": 1
        },
        "is_default": {
            "title": "Mark as default policy",
            "type": "boolean",
            "default": false
        },
        "policy_library_level": {
            "title": "Library level policy",
            "type": "boolean",
            "default": false
        },
        "libraries": {
            "title": "List of libraries",
            "type": "array",
            "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                    "$ref"
                ],
                "properties": {
                    "$ref": {
                        "title": "Library URI",
                        "type": "string",
                        "pattern": "^https://ils.rero.ch/api/libraries/.*?$"
                    }
                }
            }
        },
        "settings": {
            "title": "Patron + Item types links",
            "type": "array",
            "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                    "patron_type",
                    "item_type"
                ],
                "properties": {
                    "patron_type": {
                        "title": "Patron type",
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                            "$ref"
                        ],
                        "properties": {
                            "$ref": {
                                "title": "Patron type URI",
                                "type": "string",
                                "pattern": "^https://ils.rero.ch/api/patron_types/.*?$"
                            }
                        }
                    },
                    "item_type": {
                        "title": "Item type",
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                            "$ref"
                        ],
                        "properties": {
                            "$ref": {
                                "title": "Item type URI",
                                "type": "string",
                                "pattern": "^https://ils.rero.ch/api/item_types/.*?$"
                            }
                        }
                    }
                }
            }
        }
    }
}