{
    "id": "resource",
    "title": "Resource",
    "description": "Default resources schemas of the peritext ecosystem",
    "$schema": "http://json-schema.org/draft-06/schema#",
    "type": "object",
    "properties":
    {
        "type":
        {
            "type": "string",
            "enum": ["resource"],
            "default": "resource",
            "editable": false
        },
        "metadata":
        {
            "description": "metadata of the resource",
            "type": "object",
            "properties":
            {
                "type":
                {
                    "type": "string",
                    "enum": ["section", "image", "glossary", "images", "table", "bib", "video", "webpage", "embed"]
                },
                "title":
                {
                    "type": "string",
                    "description": "Name of the resource",
                    "default": ""
                },
                "tags": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "pattern":                        "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
                    },
                    "default": []
                },
                "authors":
                {
                    "type": "array",
                    "description": "creators of the resource",
                    "default": [],
                    "items":
                    {
                        "type": "object",
                        "properties":
                        {
                            "given":
                            {
                                "type": "string",
                                "default": ""
                            },
                            "family":
                            {
                                "type": "string",
                                "default": ""
                            },
                            "role":
                            {
                                "type": "string",
                                "default": ""
                            }
                        },
                        "required": ["given", "family"]
                    }
                },
                "description":
                {
                    "type": "string",
                    "description": "description of the resource",
                    "longString": true,
                    "default": ""
                },
                "source":
                {
                    "type": "string",
                    "description": "provenance of the resource",
                    "longString": true,
                    "default": ""
                }
            }
        },
        "data":
        {
            "default":
            {},
            "description": "data of the resource (depends on resource type)",
            "anyOfFrom": "metadata.resourceType",
            "anyOf": [
            {
                "$ref": "#/definitions/image"
            },
            {
                "$ref": "#/definitions/table"
            },
            {
                "$ref": "#/definitions/bib"
            },
            {
                "$ref": "#/definitions/video"
            },
            {
                "$ref": "#/definitions/webpage"
            },
            {
                "$ref": "#/definitions/glossary"
            },
            {
                "$ref": "#/definitions/embed"
            }]
        }
    },
    "required": ["type", "metadata", "data"],

    "definitions":
    {
        "section":
        {
          "type": "object",
          "properties": {
            "contents": {
                "$ref": "#/definitions/contents"
            }
          },
          "titlePath": ["metadata", "title"],
          "additionalProperties": false,
          "showMetadata": true
        },
        "glossary":
        {
            "type": "object",
          "titlePath": ["data", "name"],
          "properties":
            {
                "entryType": {
                    "type": "string",
                    "enum": [ "notion", "place", "event", "person", "other"]
                },
                "name": {
                    "type": "string",
                    "longString": false
                },
                "givenName": {
                    "type": "string"
                },
                "description": {
                    "type": "string",
                    "longString": true
                },
                "location":
                {
                    "type": "object",
                    "description": "geolocalization the entry",
                    "properties":
                    {
                        "latitude":
                        {
                            "type": "number"
                        },
                        "longitude":
                        {
                            "type": "number"
                        },
                        "address":
                        {
                            "type": "string"
                        }
                    }
                },
                "dates": {
                    "type": "object",
                    "description": "date bounds of the entry",
                    "properties": {
                        "start": {
                            "type": "number"
                        },
                        "end": {
                            "type": "number"
                        }
                    }
                },
                "contents": {
                    "type": "object"
                }
            },
            "showMetadata": false,
            "titlePath": ["data", "name"],
            "additionalProperties": false
        },
        "image":
        {
            "type": "object",
            "properties": {
                "images": {
                    "type": "array",
                    "default": [{}],
                    "items":
                    {
                        "type": "object",
                        "properties":
                        {
                            "rgbImageAssetId":
                            {
                                "type": "string",
                                "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                                "description": "rgb/rvb image asset uuid of the resource",
                                "acceptMimetypes": ["image/png","image/svg+xml", "image/jpeg", "image/jpg", "image/gif"]
                            },
                            "cmybImageAssetId":
                            {
                                "type": "string",
                                "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                                "description": "cmyb/cmjn image asset uuid of the resource",
                                "acceptMimetypes": ["image/png","image/svg+xml", "image/jpeg", "image/jpg", "image/gif"]
                            },
                            "caption": {
                                "type": "string",
                                "description": "image-specific caption"
                            }
                        }
                    }
                },
                "contents": {
                    "type": "object"
                }
            },
            "showMetadata": true,
            "additionalProperties": false
        },
        "table":
        {
          "type": "object",
          "properties": {
            "dataAssetId":
            {
              "type": "string",
              "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
              "description": "data asset uuid of the resource",
              "acceptMimetypes": ["text/csv", "text/tsv", "text/tab-separated-values", "text/comma-separated-values"]
            },
            "contents": {
                "type": "object"
            }
          },
          "showMetadata": true,
          "additionalProperties": false
        },
        "video":
        {
          "type": "object",
          "showMetadata": true,
          "properties": {
            "mediaUrl": {
              "type": "string",
              "description": "url of the video"
            },
            "rgbImageAssetId":
            {
                "type": "string",
                "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                "description": "rgb/rvb image asset uuid of the resource",
                "acceptMimetypes": ["image/png","image/svg+xml", "image/jpeg", "image/jpg", "image/gif"]
            },
            "cmybImageAssetId":
            {
                "type": "string",
                "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                "description": "cmyb/cmjn image asset uuid of the resource",
                "acceptMimetypes": ["image/png","image/svg+xml", "image/jpeg", "image/jpg", "image/gif"]
            },
            "contents": {
                "type": "object"
            }
          },
          "additionalProperties": false
        },
        "embed":
        {
          "type": "object",
          "showMetadata": true,
          "properties": {
            "html": {
              "type": "string",
              "longString": true,

              "description": "embed code of the resource"
            },
            "rgbImageAssetId":
            {
                "type": "string",
                "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                "description": "rgb/rvb image asset uuid of the resource",
                "acceptMimetypes": ["image/png","image/svg+xml", "image/jpeg", "image/jpg", "image/gif"]
            },
            "cmybImageAssetId":
            {
                "type": "string",
                "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                "description": "cmyb/cmjn image asset uuid of the resource",
                "acceptMimetypes": ["image/png","image/svg+xml", "image/jpeg", "image/jpg", "image/gif"]
            },
            "contents": {
                "type": "object"
            }
          },
          "additionalProperties": false
        },
        "bib":
        {
          "type": "object",
          "properties": {
            "contents": {
                "type": "object"
            },
            "citations": {
                "type": "array"
            }
          },
          "titlePath": ["data", "citations", 0, "title"],
          
          "metadataEditable": false,
          "showAssetPreview": true
        },
        "webpage":
        {
          "type": "object",
          "properties": {
            "url":
            {
              "type": "string",
              "description": "url of the webpage view"
            },
            "contents": {
                "type": "object"
            }
          },
          "additionalProperties": false,
          "showMetadata": true
        },
        "contents": {
            "type": "object",
            "properties": {
                "contents": {
                    "description": "representation of main contents",
                    "$ref": "#/definitions/draftRawContents"
                },
                "notes": {
                    "type": "object",
                    "description": "map of notes commenting a section",
                    "default": {},
                    "patternProperties": {
                        "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string",
                                    "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                                    "description": "id of the note (uuid v4)"
                                },
                                "order": {
                                    "type": "number",
                                    "description": "order of the note"
                                },
                                "contents": {
                                    "description": "representation of the note content",
                                    "$ref": "#/definitions/draftRawContents"
                                }
                            }
                        }
                    }
                },
                "notesOrder": {
                    "type": "array",
                    "description": "Order of the notes commenting the main contents",
                    "default": []
                }
            }
        },

        "draftRawContents": {
            "type": "object",
            "properties": {
                "entityMap": {
                    "type": "object",
                    "description": "List of entities annotating the contents",
                    "default": {},
                    "patternProperties": {
                        "^[a-zA-Z0-9]*$": {
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "description": "Custom type of the entity (examples in peritext: INLINE_ASSET, BLOCK_ASSET, NOTE_POINTER)"
                                },
                                "mutability": {
                                    "type": "string",
                                    "description": "Whether the entity is editable in a draft-js editor"
                                },
                                "data": {
                                    "type": "object",
                                    "description": "data to embed in the entity"
                                }
                            }
                        }
                    }
                },

                "blocks": {
                    "type": "array",
                    "description": "List of contents blocks of the item",
                    "default": [],
                    "items": {
                        "type": "object",
                        "properties": {
                            "key": {
                                "type": "string",
                                "description": "identifier of the block"
                            },
                            "text": {
                                "type": "string",
                                "description": "Text of the block"
                            },
                            "type": {
                                "type": "string",
                                "description": "Type of block (atomic, ...)"
                            },
                            "depth": {
                                "type": "number"
                            },
                            "inlineStyleRanges": {
                                "type": "array",
                                "description": "list of styling annotations"
                            },
                            "entityRanges": {
                                "type": "array",
                                "description": "List of entities mentions"
                            },
                            "data": {
                                "type": "object"
                            }
                        }
                    }
                }

            }
        }
    }
}
