{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://go.kicad.org/pcm/schemas/v1",
    "title": "KiCad PCM schema",
    "description": "KiCad Plugin and Content Manager repository and package metadata schema",
    "$ref": "#/definitions/Package",
    "definitions": {
        "Package": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "Package name",
                    "maxLength": 200
                },
                "description": {
                    "type": "string",
                    "description": "Short package description",
                    "maxLength": 500
                },
                "description_full": {
                    "type": "string",
                    "description": "Long package description",
                    "maxLength": 5000
                },
                "identifier": {
                    "type": "string",
                    "description": "Package identifier",
                    "pattern": "^[a-zA-Z][-a-zA-Z0-9.]{0,98}[a-zA-Z0-9]$"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "plugin",
                        "library",
                        "colortheme"
                    ],
                    "description": "Type of the package"
                },
                "author": {
                    "$ref": "#/definitions/Contact",
                    "description": "Author of the package"
                },
                "maintainer": {
                    "$ref": "#/definitions/Contact",
                    "description": "Maintainer of the package"
                },
                "license": {
                    "$ref": "#/definitions/License",
                    "description": "Package distribution license"
                },
                "resources": {
                    "type": "object",
                    "description": "Additional resource links for the package",
                    "patternProperties": {
                        "^[a-zA-Z][-a-zA-Z0-9 ]{0,48}[a-zA-Z0-9]$": {
                            "type": "string",
                            "maxLength": 500
                        }
                    },
                    "additionalProperties": false
                },
                "tags": {
                    "type": "array",
                    "description": "Tags for the package",
                    "items": {
                        "type": "string",
                        "pattern": "^[a-z][-a-z0-9]{0,48}[a-z0-9]$"
                    },
                    "minItems": 1,
                    "uniqueItems": true
                },
                "versions": {
                    "type": "array",
                    "description": "Package versions",
                    "items": {
                        "$ref": "#/definitions/PackageVersion"
                    },
                    "uniqueItems": true
                }
            },
            "required": [
                "name",
                "description",
                "description_full",
                "identifier",
                "type",
                "author",
                "license",
                "resources",
                "versions"
            ]
        },
        "Contact": {
            "type": "object",
            "description": "Contact information",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "Contact's name",
                    "maxLength": 500
                },
                "contact": {
                    "type": "object",
                    "description": "Contact information details",
                    "patternProperties": {
                        "^[a-z][-a-z0-9 ]{0,48}[a-z0-9]$": {
                            "type": "string",
                            "maxLength": 500
                        }
                    },
                    "additionalProperties": false
                }
            },
            "required": [
                "name",
                "contact"
            ]
        },
        "PackageVersion": {
            "type": "object",
            "description": "Package version details",
            "properties": {
                "version": {
                    "type": "string",
                    "description": "Package version number major[.minor[.patch]]",
                    "pattern": "^\\d{1,4}(\\.\\d{1,4}(\\.\\d{1,6})?)?$"
                },
                "version_epoch": {
                    "type": "integer",
                    "description": "Version epoch number. Versions with higher epoch will be considered later.",
                    "minimum": 0
                },
                "download_url": {
                    "description": "URL for direct download of the package archive",
                    "$ref": "#/definitions/URL"
                },
                "download_sha256": {
                    "type": "string",
                    "description": "SHA-256 hash of the package archive as lower case hex string",
                    "pattern": "^[a-f0-9]{64}$"
                },
                "download_size": {
                    "description": "Download size in bytes",
                    "type": "integer",
                    "minimum": 0
                },
                "install_size": {
                    "description": "Extracted size in bytes",
                    "type": "integer",
                    "minimum": 0
                },
                "status": {
                    "type": "string",
                    "description": "Development status of the package version",
                    "enum": [
                        "stable",
                        "testing",
                        "development",
                        "deprecated"
                    ]
                },
                "platforms": {
                    "type": "array",
                    "description": "Supported platforms",
                    "items": {
                        "type": "string",
                        "enum": [
                            "windows",
                            "macos",
                            "linux"
                        ]
                    },
                    "minItems": 1,
                    "uniqueItems": true
                },
                "kicad_version": {
                    "type": "string",
                    "description": "Minimum supported KiCad version",
                    "pattern": "^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$"
                },
                "kicad_version_max": {
                    "type": "string",
                    "description": "Maximum supported KiCad version",
                    "pattern": "^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$"
                }
            },
            "required": [
                "version",
                "status",
                "kicad_version"
            ]
        },
        "PackageArray": {
            "type": "object",
            "description": "Array of package descriptions",
            "properties": {
                "packages": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Package"
                    }
                }
            },
            "required": [
                "packages"
            ]
        },
        "Repository": {
            "type": "object",
            "description": "Repository metadata",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "Repository name",
                    "maxLength": 500
                },
                "packages": {
                    "description": "Reference to repository packages metadata",
                    "$ref": "#/definitions/RepositoryResource"
                },
                "resources": {
                    "description": "Reference to additional resource files archive",
                    "$ref": "#/definitions/RepositoryResource"
                },
                "manifests": {
                    "description": "Reference to package manifests",
                    "$ref": "#/definitions/RepositoryResource"
                },
                "maintainer": {
                    "description": "Repository maintainer",
                    "$ref": "#/definitions/Contact"
                },
                "$schema": {
                    "$ref": "#/definitions/URL"
                }
            },
            "required": [
                "name",
                "packages"
            ]
        },
        "RepositoryResource": {
            "type": "object",
            "properties": {
                "url": {
                    "$ref": "#/definitions/URL"
                },
                "sha256": {
                    "type": "string",
                    "description": "SHA-256 hash of the resource file as lower case hex string",
                    "pattern": "^[a-f0-9]{64}$"
                },
                "update_timestamp": {
                    "type": "integer",
                    "description": "Update timestamp of the resource file"
                },
                "update_time_utc": {
                    "type": "string",
                    "description": "Human readabla update time in UTC YYYY-MM-DD HH:MM:SS format",
                    "pattern": "^2\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d$"
                }
            },
            "required": [
                "url",
                "update_timestamp"
            ]
        },
        "URL": {
            "type": "string",
            "pattern": "^(https?:\\/\\/[^\\s\\/$.?#].[^\\s]*)|(file:\\/\\/([a-zA-Z]:|\\/)[^\\x00]+)$"
        },
        "License": {
            "type": "string",
            "enum": [
                "public-domain",
                "Apache",
                "Apache-1.0",
                "Apache-2.0",
                "Artistic",
                "Artistic-1.0",
                "Artistic-2.0",
                "BSD",
                "BSD-2-Clause",
                "BSD-3-Clause",
                "BSD-4-Clause",
                "ISC",
                "CC-BY",
                "CC-BY-1.0",
                "CC-BY-2.0",
                "CC-BY-2.5",
                "CC-BY-3.0",
                "CC-BY-4.0",
                "CC-BY-SA",
                "CC-BY-SA-1.0",
                "CC-BY-SA-2.0",
                "CC-BY-SA-2.5",
                "CC-BY-SA-3.0",
                "CC-BY-SA-4.0",
                "CC-BY-ND",
                "CC-BY-ND-1.0",
                "CC-BY-ND-2.0",
                "CC-BY-ND-2.5",
                "CC-BY-ND-3.0",
                "CC-BY-ND-4.0",
                "CC-BY-NC",
                "CC-BY-NC-1.0",
                "CC-BY-NC-2.0",
                "CC-BY-NC-2.5",
                "CC-BY-NC-3.0",
                "CC-BY-NC-4.0",
                "CC-BY-NC-SA",
                "CC-BY-NC-SA-1.0",
                "CC-BY-NC-SA-2.0",
                "CC-BY-NC-SA-2.5",
                "CC-BY-NC-SA-3.0",
                "CC-BY-NC-SA-4.0",
                "CC-BY-NC-ND",
                "CC-BY-NC-ND-1.0",
                "CC-BY-NC-ND-2.0",
                "CC-BY-NC-ND-2.5",
                "CC-BY-NC-ND-3.0",
                "CC-BY-NC-ND-4.0",
                "CC0-1.0",
                "CDDL-1.0",
                "CPL",
                "EFL",
                "EFL-1.0",
                "EFL-2.0",
                "MIT",
                "GPL",
                "GPL-1.0",
                "GPL-2.0",
                "GPL-3.0",
                "LGPL",
                "LGPL-2.1",
                "LGPL-3.0",
                "GNU-LGPL-2.0",
                "GFDL",
                "GFDL-1.0",
                "GFDL-1.1",
                "GFDL-1.2",
                "GFDL-1.3",
                "GFDL-NIV",
                "LPPL",
                "LPPL-1.0",
                "LPPL-1.1",
                "LPPL-1.2",
                "LPPL-1.3",
                "MPL-1.1",
                "Perl",
                "Python-2.0",
                "QPL-1.0",
                "W3C",
                "Zlib",
                "Zope",
                "Zope-1.0",
                "Zope-1.1",
                "Zope-2.0",
                "Zope-2.1",
                "CERN-OHL",
                "WTFPL",
                "Unlicense",
                "open-source",
                "unrestricted"
            ]
        }
    }
}