{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://omeka-s-contrib.github.io/omeka-s-blueprints/schema/v0.2.0/blueprint-schema.json",
    "title": "Omeka S Blueprint",
    "description": "Declarative description of an Omeka S environment.",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "$schema": { "type": "string" },
        "meta": {
            "type": "object",
            "description": "Human-readable metadata.",
            "additionalProperties": false,
            "properties": {
                "title": { "type": "string" },
                "author": { "type": "string" },
                "description": { "type": "string" }
            }
        },
        "preferredVersions": {
            "type": "object",
            "description": "The PHP and Omeka S versions the blueprint was written for. When consumers install Omeka S and install.source is absent, omeka is the release they install; consumers that cannot choose the version treat it as a hint.",
            "additionalProperties": false,
            "properties": {
                "php": { "type": "string" },
                "omeka": { "type": "string" }
            }
        },
        "install": {
            "type": "object",
            "description": "Values used when installing Omeka S. Consumers that work on an existing installation ignore them.",
            "additionalProperties": false,
            "properties": {
                "source": {
                    "$ref": "#/$defs/datasource.file",
                    "description": "Omeka S release ZIP, the built release asset (not a GitHub source archive): a URL, a relative path or a file in a repository. Consumers reject a git repository. When it can't be read, consumers stop with an error; they don't fall back to preferredVersions.omeka. Without it, consumers install the release named by preferredVersions.omeka, or their default release."
                },
                "title": { "type": "string" },
                "locale": { "type": "string" },
                "timezone": { "type": "string" },
                "admin": {
                    "type": "object",
                    "description": "First global administrator. Consumers may take the password from their own input (flags, environment) or generate it.",
                    "additionalProperties": false,
                    "required": ["email"],
                    "properties": {
                        "name": { "type": "string" },
                        "email": { "type": "string", "format": "email" },
                        "password": { "type": "string", "minLength": 1 }
                    }
                }
            }
        },
        "modules": { "$ref": "#/$defs/moduleList" },
        "themes": { "$ref": "#/$defs/themeList" },
        "files": { "$ref": "#/$defs/fileList" },
        "vocabularies": { "$ref": "#/$defs/vocabularyList" },
        "resourceTemplates": { "$ref": "#/$defs/resourceTemplateList" },
        "settings": { "$ref": "#/$defs/settings" },
        "users": { "$ref": "#/$defs/userList" },
        "itemSets": { "$ref": "#/$defs/itemSetList" },
        "items": { "$ref": "#/$defs/itemList" },
        "sites": { "$ref": "#/$defs/siteList" }
    },
    "patternProperties": {
        "^x-": {
            "description": "Implementation-specific extension (e.g. x-playground, x-omeka-s-cli). Its content is defined by that implementation; other consumers ignore it."
        }
    },

    "$defs": {
        "reference": {
            "type": "object",
            "description": "A pointer to an external file or URL whose contents are spliced into the enclosing list. The referenced document is itself a valid list (or single item) for that key.",
            "additionalProperties": false,
            "required": ["$import"],
            "properties": {
                "$import": { "$ref": "#/$defs/datasource.file" }
            }
        },

        "datasource.relativePath": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(?![A-Za-z][A-Za-z0-9+.-]*:)(?!git@[^/:]*:)(?![/\\\\\\s])",
            "description": "Path relative to the declaring document: no scheme, not absolute, no leading whitespace. A URL reference: resolved against the declaring document, and decoded only to read a local file. It must stay inside the root. './' is recommended."
        },
        "datasource.url": {
            "type": "string",
            "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://[^/?#]+",
            "description": "An http(s) URL. A URL whose path ends in .git, or https://github.com/OWNER/REPO (with or without a trailing /), is a git repository; any other URL is a file."
        },
        "datasource.git": {
            "type": "string",
            "pattern": "^(?:gh:|gl:|git@[^/:]*:)",
            "description": "A git source: gh:owner/repo[#ref], gh:owner/repo[@ref]:path, gl:group/repo[@ref]:path or git@host:path.git[#ref]."
        },
        "datasource.source": {
            "description": "A source: relative path, URL or git source. The schema identifies the form; the consumer resolves it.",
            "anyOf": [
                { "$ref": "#/$defs/datasource.relativePath" },
                { "$ref": "#/$defs/datasource.url" },
                { "$ref": "#/$defs/datasource.git" }
            ]
        },
        "datasource.file": {
            "x-blueprint-reference": "resource",
            "$ref": "#/$defs/datasource.source",
            "description": "A single file, resolved against the declaring document."
        },

        "omeka.addonSource": {
            "x-blueprint-reference": "addon",
            "description": "Module or theme: ZIP or git repository. A ZIP or a #ref wins over version. Without it, the installed add-on is used, else a catalog lookup by name.",
            "$ref": "#/$defs/datasource.source"
        },
        "addonSource": { "$ref": "#/$defs/omeka.addonSource", "deprecated": true, "description": "Deprecated alias of omeka.addonSource, kept for external references to v0.1.0." },

        "instancePath": {
            "type": "string",
            "description": "Path relative to the Omeka S installation root. Absolute paths and '..' segments are not allowed.",
            "pattern": "^(?![/\\\\])(?![A-Za-z]:)(?!(?:.*[/\\\\])?\\.\\.(?:[/\\\\]|$)).+$"
        },

        "moduleId": {
            "type": "string",
            "description": "Omeka S module identifier (equal to the module's directory name).",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]*$"
        },
        "addonVersion": {
            "type": "string",
            "description": "Release to use when resolving through omeka.org, or tag/branch for a git repository. A source that pins a release or ref (a ZIP, or a #ref) wins; consumers may warn when they differ."
        },
        "module": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name"],
            "properties": {
                "name": { "$ref": "#/$defs/moduleId" },
                "state": {
                    "type": "string",
                    "description": "download = place files only; install = install; activate = install and enable.",
                    "enum": ["download", "install", "activate"]
                },
                "version": { "$ref": "#/$defs/addonVersion" },
                "source": { "$ref": "#/$defs/omeka.addonSource" }
            }
        },
        "moduleList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/moduleId" },
                    { "$ref": "#/$defs/module" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "themeId": {
            "type": "string",
            "description": "Omeka S theme identifier (equal to the theme's directory name).",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]*$"
        },
        "theme": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name"],
            "properties": {
                "name": { "$ref": "#/$defs/themeId" },
                "version": { "$ref": "#/$defs/addonVersion" },
                "source": { "$ref": "#/$defs/omeka.addonSource" }
            }
        },
        "themeList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/themeId" },
                    { "$ref": "#/$defs/theme" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "file": {
            "type": "object",
            "description": "A file placed in the Omeka S installation (e.g. config/cleanurl.config.php), applied after modules and themes are in place.",
            "additionalProperties": false,
            "required": ["source", "destination"],
            "properties": {
                "source": {
                    "$ref": "#/$defs/datasource.file",
                    "description": "Path or URL of the file. Relative paths resolve against the file that declares them."
                },
                "destination": {
                    "$ref": "#/$defs/instancePath",
                    "description": "Path relative to the Omeka S root. Absolute paths and '..' segments are not allowed. With extract, the directory to extract into."
                },
                "extract": {
                    "type": "boolean",
                    "default": false,
                    "description": "Treat source as a ZIP archive and extract it into destination. If the archive has a single top-level directory, its contents are extracted, as with add-on archives."
                }
            }
        },
        "fileList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/file" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "vocabulary": {
            "type": "object",
            "description": "A vocabulary to import via the RDF importer.",
            "additionalProperties": false,
            "required": ["source", "namespaceUri", "prefix", "label"],
            "properties": {
                "source": {
                    "$ref": "#/$defs/datasource.file",
                    "description": "Path or URL of the RDF file. Relative paths resolve against the file that declares them."
                },
                "namespaceUri": { "type": "string" },
                "prefix": { "type": "string" },
                "label": { "type": "string" },
                "comment": { "type": "string" },
                "format": { "type": "string" },
                "lang": { "type": "string" },
                "labelProperty": { "type": "string", "description": "RDF property to use for labels." },
                "commentProperty": { "type": "string", "description": "RDF property to use for comments." }
            }
        },
        "vocabularyList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/vocabulary" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "resourceTemplate": {
            "type": "object",
            "additionalProperties": false,
            "required": ["source"],
            "properties": {
                "source": {
                    "$ref": "#/$defs/datasource.file",
                    "description": "Path or URL to a resource-template JSON export."
                },
                "label": { "type": "string" },
                "ignoreDeps": { "type": "boolean" }
            }
        },
        "resourceTemplateList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/resourceTemplate" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "settingsMap": {
            "type": "object",
            "description": "A map of global setting id => value.",
            "additionalProperties": true
        },
        "settings": {
            "description": "Global settings. Either an inline map, or a list of maps/references merged in order.",
            "oneOf": [
                {
                    "allOf": [
                        { "$ref": "#/$defs/settingsMap" },
                        { "not": { "required": ["$import"] } }
                    ]
                },
                {
                    "type": "array",
                    "items": {
                        "oneOf": [
                            {
                                "allOf": [
                                    { "$ref": "#/$defs/settingsMap" },
                                    { "not": { "required": ["$import"] } }
                                ]
                            },
                            { "$ref": "#/$defs/reference" }
                        ]
                    }
                }
            ]
        },

        "user": {
            "type": "object",
            "additionalProperties": false,
            "required": ["email"],
            "properties": {
                "email": { "type": "string", "format": "email" },
                "username": { "type": "string" },
                "password": { "type": "string", "minLength": 1 },
                "role": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Omeka S role id. Core roles: global_admin, site_admin, editor, reviewer, author, researcher. Modules can register more (e.g. guest)."
                },
                "isActive": { "type": "boolean" },
                "settings": {
                    "type": "object",
                    "description": "Per-user settings written to user_setting (e.g. limit_to_granted_sites).",
                    "additionalProperties": true
                }
            }
        },
        "siteList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/site" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },
        "userList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/user" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "itemSet": {
            "type": "object",
            "additionalProperties": false,
            "required": ["title"],
            "properties": {
                "title": { "type": "string" },
                "description": { "type": "string" },
                "onError": { "$ref": "#/$defs/onError" }
            }
        },
        "itemSetList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/itemSet" },
                    { "$ref": "#/$defs/itemSetSource" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "onError": {
            "type": "string",
            "enum": ["fail", "skip"],
            "default": "fail",
            "description": "What a consumer does when this entry cannot be applied: fail stops the deploy, skip leaves the entry out and reports a warning."
        },
        "itemSetSource": {
            "type": "object",
            "additionalProperties": false,
            "required": ["source"],
            "properties": {
                "source": {
                    "$ref": "#/$defs/datasource.file",
                    "description": "Path or URL to a portable JSON-LD file: one resource, with an inline @context, that names the records it refers to with o-ref terms (https://omeka-s-contrib.github.io/omeka-s-ref/ns) instead of instance ids. A relative path resolves against the file that declares the entry."
                },
                "title": { "type": "string", "description": "The title in the file. It identifies the entry in the blueprint, lets items name this item set by title, and is used in messages." },
                "onError": { "$ref": "#/$defs/onError" }
            }
        },
        "itemSource": {
            "type": "object",
            "additionalProperties": false,
            "required": ["source"],
            "properties": {
                "source": {
                    "$ref": "#/$defs/datasource.file",
                    "description": "Path or URL to a portable JSON-LD file: one resource, with an inline @context, that names the records it refers to with o-ref terms (https://omeka-s-contrib.github.io/omeka-s-ref/ns) instead of instance ids. A relative path resolves against the file that declares the entry."
                },
                "title": { "type": "string", "description": "The title in the file. It identifies the entry in the blueprint and is used in messages." },
                "sites": {
                    "type": "array",
                    "description": "Slugs (or titles) of the sites this item is assigned to. Replaces the file's o:site.",
                    "items": { "type": "string" }
                },
                "media": { "type": "array", "items": { "$ref": "#/$defs/media" } },
                "onError": { "$ref": "#/$defs/onError" }
            }
        },

        "media": {
            "type": "object",
            "additionalProperties": false,
            "required": ["url"],
            "properties": {
                "type": { "type": "string", "enum": ["url"] },
                "url": { "$ref": "#/$defs/datasource.file" },
                "title": { "type": "string" },
                "altText": { "type": "string" }
            }
        },
        "item": {
            "type": "object",
            "additionalProperties": false,
            "required": ["title"],
            "properties": {
                "title": { "type": "string" },
                "description": { "type": "string" },
                "creator": { "type": "string" },
                "itemSets": { "type": "array", "items": { "type": "string" } },
                "sites": {
                    "type": "array",
                    "description": "Slugs (or titles) of the sites this item is assigned to. Defaults to the default site.",
                    "items": { "type": "string" }
                },
                "media": { "type": "array", "items": { "$ref": "#/$defs/media" } },
                "onError": { "$ref": "#/$defs/onError" }
            }
        },
        "itemList": {
            "type": "array",
            "items": {
                "oneOf": [
                    { "$ref": "#/$defs/item" },
                    { "$ref": "#/$defs/itemSource" },
                    { "$ref": "#/$defs/reference" }
                ]
            }
        },

        "sitePermission": {
            "type": "object",
            "additionalProperties": false,
            "required": ["user"],
            "properties": {
                "user": { "type": "string", "description": "Email of an existing blueprint user." },
                "role": { "type": "string", "enum": ["viewer", "editor", "admin"] }
            }
        },
        "site": {
            "type": "object",
            "additionalProperties": false,
            "required": ["title"],
            "properties": {
                "title": { "type": "string" },
                "slug": { "type": "string" },
                "summary": { "type": "string" },
                "theme": { "$ref": "#/$defs/themeId" },
                "isPublic": { "type": "boolean" },
                "setAsDefault": { "type": "boolean" },
                "assignNewItems": {
                    "type": "boolean",
                    "default": true,
                    "description": "Add items created later without an explicit site to this site, as the Omeka S admin form does by default. Consumers set it when they create the site."
                },
                "permissions": {
                    "type": "array",
                    "description": "Per-site user permissions, by user email.",
                    "items": { "$ref": "#/$defs/sitePermission" }
                }
            }
        }
    }
}