{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://kumori.systems/kdsl/registry-index.schema.json",
    "title": "KDSL Registry Module Index",
    "description": "Defines the structure of the index.json file hosted in a registry repository.",
    "$defs": {
        "role": {
            "type": "object",
            "required": ["name", "type", "roles"],
            "properties": {
                "name": {
                    "type": "string",
                    "description": "Role name"
                },
                "type": {
                    "type": "string",
                    "enum": ["component", "service"],
                    "description": "Type of the role"
                },
                "roles": {
                    "type": "array",
                    "minItems": 0,
                    "items": { "$ref": "#/$defs/role" },
                    "description": "Nested roles (for service roles)"
                }
            },
            "additionalProperties": false
        }
    },
    "type": "object",
    "required": ["modules"],
    "properties": {
        "modules": {
            "type": "array",
            "minItems": 0,
            "uniqueItems": true,
            "description": "List of modules available in this registry index",
            "items": {
                "type": "object",
                "required": ["domain", "version", "location", "checksum", "artifacts"],
                "properties": {
                    "domain": {
                        "type": "string",
                        "description": "Domain of the module (e.g. kumori.systems/jenkins)"
                    },
                    "version": {
                        "type": "string",
                        "description": "Semantic version of the module"
                    },
                    "description": {
                        "type": "string",
                        "description": "Optional human-readable module description"
                    },
                    "location": {
                        "type": "string",
                        "description": "Location (URL) where the module resides"
                    },
                    "releaseDate": {
                        "type": "string",
                        "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                        "description": "Release date in YYYY-MM-DD format"
                    },
                    "checksum": {
                        "type": "string",
                        "pattern": "^h1:[a-fA-F0-9]{64}$",
                        "description": "SHA-256 checksum of the module, prefixed with h1:"
                    },
                    "artifacts": {
                        "type": "array",
                        "minItems": 1,
                        "items": {
                            "type": "object",
                            "required": ["name", "type", "marketplace", "schema", "location"],
                            "properties": {
                                "name": {
                                    "type": "string",
                                    "description": "Name of the artifact"
                                },
                                "description": {
                                    "type": "string",
                                    "description": "Optional human-readable artifact description"
                                },
                                "requirements": {
                                    "type": "object",
                                    "description": "Requirements for using this artifact",
                                    "properties": {
                                        "cpu": {
                                            "type": "number",
                                            "description": "Minimum vCPUs required"
                                        },
                                        "memory": {
                                            "type": "number",
                                            "description": "Minimum memory (in GB) required"
                                        }
                                    }
                                },
                                "marketplace": {
                                    "type": "boolean",
                                    "description": "Whether this artifact is available in the marketplace"
                                },
                                "type": {
                                    "type": "string",
                                    "enum": ["component", "service"],
                                    "description": "Type of artifact"
                                },
                                "schema": {
                                    "type": "object",
                                    "description": "JSON Schema object describing the artifact"
                                },
                                "location": {
                                    "type": "string",
                                    "description": "Relative path or URL to the artifact"
                                },
                                "roles": {
                                    "type": "array",
                                    "minItems": 0,
                                    "items": { "$ref": "#/$defs/role" },
                                    "description": "List of roles exposed by this artifact"
                                },
                                "icon": {
                                    "type": "string",
                                    "description": "Filename for the artifact's icon"
                                },
                                "categories": {
                                    "type": "array",
                                    "items": { "type": "string" },
                                    "description": "Categories for this artifact"
                                },
                                "tags": {
                                    "type": "array",
                                    "items": { "type": "string" },
                                    "description": "Tags for this artifact"
                                }
                            },
                            "additionalProperties": false
                        }
                    }
                },
                "additionalProperties": false
            }
        }
    },
    "additionalProperties": false
}
