{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://vgpu.sh/schemas/native/tint-semantic-extraction/v1/request.schema.json",
    "title": "vGPU Native Tint Semantic Extraction Request v1",
    "type": "object",
    "additionalProperties": false,
    "required": [
        "schemaVersion",
        "contractId",
        "source",
        "originMap",
        "originMapSha256",
        "entryPoints",
        "overrideConfiguration",
        "languageFeatures"
    ],
    "properties": {
        "schemaVersion": { "const": 1 },
        "contractId": { "const": "vgpu-native-tint-semantic-extraction/v1" },
        "source": {
            "$ref": "https://vgpu.sh/schemas/native/tint-entry-inventory/v1/request.schema.json#/$defs/source"
        },
        "originMap": {
            "$ref": "https://vgpu.sh/schemas/native/tint-compiler/v1/origin-map.schema.json"
        },
        "originMapSha256": {
            "$ref": "https://vgpu.sh/schemas/native/tint-entry-inventory/v1/request.schema.json#/$defs/sha256"
        },
        "entryPoints": { "$ref": "#/$defs/selectedProgram" },
        "overrideConfiguration": {
            "type": "array",
            "maxItems": 4096,
            "uniqueItems": true,
            "items": { "$ref": "#/$defs/configuredOverride" }
        },
        "languageFeatures": {
            "$ref": "https://vgpu.sh/schemas/native/tint-entry-inventory/v1/request.schema.json#/properties/languageFeatures"
        }
    },
    "$defs": {
        "selectedVertex": {
            "type": "object",
            "additionalProperties": false,
            "required": ["stage", "wgsl"],
            "properties": {
                "stage": { "const": "vertex" },
                "wgsl": {
                    "$ref": "https://vgpu.sh/schemas/native/tint-compiler/v1/request.schema.json#/$defs/identifier"
                }
            }
        },
        "selectedFragment": {
            "type": "object",
            "additionalProperties": false,
            "required": ["stage", "wgsl"],
            "properties": {
                "stage": { "const": "fragment" },
                "wgsl": {
                    "$ref": "https://vgpu.sh/schemas/native/tint-compiler/v1/request.schema.json#/$defs/identifier"
                }
            }
        },
        "selectedCompute": {
            "type": "object",
            "additionalProperties": false,
            "required": ["stage", "wgsl"],
            "properties": {
                "stage": { "const": "compute" },
                "wgsl": {
                    "$ref": "https://vgpu.sh/schemas/native/tint-compiler/v1/request.schema.json#/$defs/identifier"
                }
            }
        },
        "selectedProgram": {
            "oneOf": [
                {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 1,
                    "prefixItems": [{ "$ref": "#/$defs/selectedCompute" }],
                    "items": false
                },
                {
                    "type": "array",
                    "minItems": 2,
                    "maxItems": 2,
                    "prefixItems": [
                        { "$ref": "#/$defs/selectedVertex" },
                        { "$ref": "#/$defs/selectedFragment" }
                    ],
                    "items": false
                }
            ]
        },
        "configuredOverride": {
            "type": "object",
            "additionalProperties": false,
            "required": ["identifier", "value"],
            "properties": {
                "identifier": {
                    "$ref": "#/$defs/overrideIdentifier"
                },
                "value": {
                    "oneOf": [{ "type": "boolean" }, { "type": "number" }]
                }
            }
        },
        "overrideIdentifier": {
            "description": "The WGSL pipeline-overridable constant identifier: its canonical decimal @id value when declared, otherwise its WGSL name.",
            "oneOf": [
                {
                    "$ref": "https://vgpu.sh/schemas/native/tint-compiler/v1/request.schema.json#/$defs/identifier"
                },
                {
                    "type": "string",
                    "pattern": "^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$",
                    "maxLength": 5
                }
            ]
        }
    }
}
