{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "https://raw.githubusercontent.com/nataliapc/metacatalog-msx/master/schemas/index.schema.json#",
    "name": "metacatalog-msx",
    "title": "",
    "type": "object",
    "description": "Schema for 8-bit-computer software metacataloguing",
    "required": [
        "header",
        "catalog",
        "content"
    ],
    "properties": {
        "$schema": {
            "type": "string"
        },
        "header": {
            "$ref": "#/definitions/headerType"
        },
        "catalog": {
            "$ref": "#/definitions/catalogType"
        },
        "content": {
            "$ref": "#/definitions/contentArrayType"
        },
        "extras": {
            "$ref": "#/definitions/extrasType"
        }
    },
    "additionalProperties": false,
    "definitions": {
        "headerType": {
            "description": "Header definition",
            "type": "object",
            "required": [
                "mimecrc",
                "mimetype",
                "version"
            ],
            "properties": {
                "mimecrc": {
                    "$ref": "#/definitions/crc32Type",
                    "description": "CRC32 of mimetype"
                },
                "mimetype": {
                    "type": "string",
                    "pattern": "^application/x-metacatalog-(tape|cartridge|disk)$"
                },
                "version": {
                    "type": "string",
                    "pattern": "^\\d+\\.\\d{1,2}\\.\\d{1,2}$"
                }
            },
            "additionalProperties": false
        },
        "catalogType": {
            "description": "Catalog info definition",
            "type": "object",
            "required": [
                "id",
                "updated",
                "platform",
                "type",
                "name",
                "license"
            ],
            "properties": {
                "id": {
                    "$ref": "#/definitions/idCatalogType"
                },
                "updated": {
                    "$ref": "#/definitions/datetimeType"
                },
                "platform": {
                    "enum": [
                        "MSX",
                        "MSX2",
                        "MSX2+",
                        "Turbo-R"
                    ]
                },
                "type": {
                    "enum": [
                        "game",
                        "application",
                        "demoscene"
                    ]
                },
                "name": {
                    "type": "string"
                },
                "name.original": {
                    "type": "string"
                },
                "name.transliterated": {
                    "type": "string"
                },
                "company": {
                    "type": "string"
                },
                "publisher": {
                    "type": "string"
                },
                "code": {
                    "type": "string",
                    "description": "Game serial code"
                },
                "license": {
                    "enum": [
                        "unknown",
                        "copyleft",
                        "commercial"
                    ]
                },
                "date": {
                    "type": "integer",
                    "minimum": 1982
                },
                "country": {
                    "type": "string"
                },
                "sound": {
                    "type": "array",
                    "minItems": 1,
                    "_uniqueItems": true,
                    "items": {
                        "enum": [
                            "PSG",
                            "OPLL",
                            "SCC",
                            "SCC+",
                            "MSX-Audio",
                            "OPL4"
                        ]
                    }
                },
                "genre": {
                    "type": "array",
                    "minItems": 1,
                    "_uniqueItems": true,
                    "items": {
                        "enum": [
                            "action",
                            "adventure",
                            "isometric",
                            "puzzle",
                            "shooter",
                            "arcade",
                            "platforms",
                            "strategy",
                            "others"
                        ]
                    }
                },
                "language": {
                    "type": "array",
                    "minItems": 1,
                    "_uniqueItems": true,
                    "items": {
                        "enum": [
                            "en",
                            "jp",
                            "es",
                            "nl",
                            "br",
                            "fr",
                            "it"
                        ]
                    }
                },
                "controls": {
                    "type": "array",
                    "minItems": 1,
                    "_uniqueItems": true,
                    "items": {
                        "enum": [
                            "keyboard",
                            "joystick",
                            "mouse"
                        ]
                    }
                },
                "developers": {
                    "type": "array",
                    "_uniqueItems": true,
                    "items": {
                        "$ref": "#/definitions/developerType"
                    }
                },
                "instructions": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "idCatalogType": {
            "description": "Id for catalogType object",
            "type": "object",
            "required": [
                "string",
                "crc32",
                "md5",
                "sha1"
            ],
            "properties": {
                "string": {
                    "type": "string",
                    "pattern": "^\\w+(|\\.[\\w,]+)*$"
                },
                "crc32": {
                    "$ref": "#/definitions/crc32Type"
                },
                "md5": {
                    "$ref": "#/definitions/md5Type"
                },
                "sha1": {
                    "$ref": "#/definitions/sha1Type"
                }
            },
            "additionalProperties": false
        },
        "developerType": {
            "description": "Developer name, task and an optional email",
            "type": "object",
            "required": [
                "name",
                "task"
            ],
            "properties": {
                "name": {
                    "type": "string"
                },
                "task": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "contentArrayType": {
            "description": "Content to catalog.",
            "type": "array",
            "minItems": 1,
            "items": {
                "$rel": "#/definitions/contentItemType"
            }
        },
        "contentItemType": {
            "description": "Item file of main content folder",
            "type": "object",
            "required": [
                "id",
                "mimetype",
                "file",
                "hash.sha1"
            ],
            "properties": {
                "id": {
                    "$rel": "#/definitions/idContentType"
                },
                "mimetype": {
                    "type": "string"
                },
                "format": {
                    "type": "string",
                    "description": "Aditional content format info."
                },
                "file": {
                    "$ref": "#/definitions/contentFileType"
                },
                "hash.sha1": {
                    "$ref": "#/definitions/sha1Type"
                },
                "start.command": {
                    "type": "string",
                    "description": "BLOAD or RUN commands"
                },
                "related.images": {
                    "description": "Im\u00e1genes relacionadas",
                    "type": "array",
                    "minItems": 1,
                    "_uniqueItems": true,
                    "items": {
                        "type": "string"
                    }
                },
                "alternates": {
                    "type": "array",
                    "minItems": 1,
                    "_uniqueItems": true,
                    "items": {
                        "$rel": "#/definitions/contentAlternateType"
                    }
                }
            },
            "patternProperties": {
                "^label(\\.[a-z]{2}){0,1}$": {
                    "type": "string"
                },
                "^comment(\\.[a-z]{2}){0,1}$": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "contentAlternateType": {
            "type": "object",
            "required": [
                "id",
                "mimetype",
                "file",
                "hash.sha1"
            ],
            "properties": {
                "id": {
                    "$rel": "#/definitions/idContentType"
                },
                "mimetype": {
                    "type": "string"
                },
                "format": {
                    "type": "string",
                    "description": "Aditional content format info."
                },
                "file": {
                    "$ref": "#/definitions/contentFileType"
                },
                "hash.sha1": {
                    "$ref": "#/definitions/sha1Type"
                }
            },
            "patternProperties": {
                "^comment(\\.[a-z]{2}){0,1}$": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "idContentType": {
            "oneOf": [
                {
                    "type": "string",
                    "pattern": "^tape\\d+(\\.side[A-Z](\\.part\\d+){0,1}){0,1}$(\\.alt\\d+){0,1}"
                },
                {
                    "type": "string",
                    "pattern": "^disk\\d+(\\.alt\\d+){0,1}$"
                },
                {
                    "type": "string",
                    "pattern": "^rom\\d+(\\.alt\\d+){0,1}$"
                }
            ],
            "description": "Use https://regex101.com to validate ids"
        },
        "extrasType": {
            "description": "Extra content",
            "type": "object",
            "properties": {
                "maintheme": {
                    "$ref": "#/definitions/extraFileType"
                },
                "images": {
                    "$ref": "#/definitions/imageArrayType"
                },
                "tips": {
                    "type": "array",
                    "_uniqueItems": true,
                    "items": {
                        "$ref": "#/definitions/tipsType"
                    }
                },
                "cheats": {
                    "type": "array",
                    "_uniqueItems": true,
                    "items": {
                        "$ref": "#/definitions/cheatsType"
                    }
                }
            },
            "additionalProperties": false
        },
        "imageArrayType": {
            "description": "To launchers: get main game image in this order by availability 'screen.loading', 'screen.ingame.menu', 'screen.ingame.1', and the image with true default attribute.",
            "type": "array",
            "minItems": 1,
            "_uniqueItems": true,
            "items": {
                "$ref": "#/definitions/imageItemType"
            }
        },
        "imageItemType": {
            "type": "object",
            "required": [
                "id",
                "file",
                "hash.sha1",
                "label"
            ],
            "properties": {
                "id": {
                    "anyOf": [
                        {
                            "type": "string",
                            "pattern": "^screen\\.(loading|ingame\\.(menu|end|\\d+))$"
                        },
                        {
                            "type": "string",
                            "pattern": "^scan\\.tape\\d+\\.(inlay(Front|Back)|side[A-B])$"
                        },
                        {
                            "type": "string",
                            "pattern": "^scan\\.disk\\d+$"
                        },
                        {
                            "type": "string",
                            "pattern": "^scan\\.rom\\.(inlay(Front|Back))$"
                        },
                        {
                            "type": "string",
                            "pattern": "^scan\\.manual\\d+$"
                        },
                        {
                            "type": "string",
                            "pattern": "^custom\\.(coverhd|gamemap)$"
                        }
                    ]
                },
                "file": {
                    "$ref": "#/definitions/imageFileType"
                },
                "hash.sha1": {
                    "$ref": "#/definitions/sha1Type"
                },
                "default": {
                    "type": "boolean"
                }
            },
            "patternProperties": {
                "^label(\\.[a-z]{2}){0,1}$": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "tipsType": {
            "description": "Tips item",
            "type": "object",
            "required": [
                "label",
                "description"
            ],
            "patternProperties": {
                "^label(\\.[a-z]{2}){0,1}$": {
                    "type": "string"
                },
                "^description(\\.[a-z]{2}){0,1}$": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "cheatsType": {
            "description": "Need definition"
        },
        "imageFileType": {
            "type": "string",
            "pattern": "^extras/[^/]+\\.(jpg|png|gif)$"
        },
        "extraFileType": {
            "type": "string",
            "pattern": "^extras/[^/]+$"
        },
        "contentFileType": {
            "type": "string",
            "pattern": "^content/[^/]+\\.(cas|rom|dsk)$"
        },
        "datetimeType": {
            "type": "string",
            "pattern": "^\\d{4}(-\\d{2}){0,2}( \\d{2}(:\\d{2}){1,2}){0,1}$",
            "description": "Date-time format 'YYYY-MM-DD [HH:MM:[SS]]'"
        },
        "crc32Type": {
            "type": "string",
            "pattern": "^[0-9a-f]{8}$",
            "description": "To generate CRC32 use: http://hash-functions.online-domain-tools.com/"
        },
        "md5Type": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$",
            "description": "To generate MD5 use: http://hash-functions.online-domain-tools.com/"
        },
        "sha1Type": {
            "type": "string",
            "pattern": "^[0-9a-f]{40}$",
            "description": "To generate SHA1 use: http://hash-functions.online-domain-tools.com/"
        },
        "hashType": {
            "description": "File hash",
            "type": "object",
            "required": [
                "crc32",
                "md5",
                "sha1"
            ],
            "properties": {
                "crc32": {
                    "$ref": "#/definitions/crc32Type"
                },
                "md5": {
                    "$ref": "#/definitions/md5Type"
                },
                "sha1": {
                    "$ref": "#/definitions/sha1Type"
                }
            },
            "additionalProperties": false
        }
    }
}