{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://lintel.aylith.com/schema/lintel-1.json",
    "title": "Lintel integration manifest, version 1",
    "type": "object",
    "required": [
        "id"
    ],
    "additionalProperties": true,
    "_comment": "additionalProperties is true ON PURPOSE. The spec requires a host to ignore keys it does not know, so a schema that rejected them would contradict the versioning rule it is meant to police.",
    "properties": {
        "id": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[a-z0-9][a-z0-9-]*$"
        },
        "name": {
            "type": "string"
        },
        "icon": {
            "type": "string"
        },
        "version": {
            "type": "integer",
            "minimum": 1
        },
        "cacheSeconds": {
            "type": "number"
        },
        "settings": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/field"
            }
        },
        "credentials": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/field"
            }
        },
        "matchers": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/matcher"
            }
        },
        "fetch": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/step"
            }
        },
        "fields": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/display"
            }
        },
        "fieldGroups": {
            "type": "array",
            "items": {
                "type": "object",
                "required": [
                    "key",
                    "fields"
                ],
                "properties": {
                    "key": {
                        "type": "string"
                    },
                    "label": {
                        "type": "string"
                    },
                    "fields": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "tabs": {
            "type": "array",
            "items": {
                "type": "object",
                "required": [
                    "key"
                ]
            }
        },
        "actions": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/action"
            }
        },
        "detectPatterns": {
            "type": "array",
            "items": {
                "type": "string",
                "format": "regex"
            }
        },
        "html": {
            "type": "string"
        },
        "account": {
            "type": "object",
            "properties": {
                "provider": {
                    "enum": [
                        "github",
                        "jira",
                        "slack"
                    ]
                }
            },
            "required": [
                "provider"
            ]
        }
    },
    "$defs": {
        "field": {
            "type": "object",
            "required": [
                "key"
            ],
            "properties": {
                "key": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                },
                "placeholder": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                },
                "default": {
                    "type": "string"
                },
                "required": {
                    "type": "boolean"
                },
                "secret": {
                    "type": "boolean",
                    "description": "Credentials only. Defaults true unless the key is email, user or username."
                },
                "editor": {
                    "enum": [
                        "text",
                        "toggle",
                        "github-owners",
                        "github-repo-owners"
                    ]
                }
            }
        },
        "matcher": {
            "type": "object",
            "required": [
                "kind",
                "pattern"
            ],
            "properties": {
                "kind": {
                    "enum": [
                        "link",
                        "text"
                    ]
                },
                "pattern": {
                    "type": "string",
                    "format": "regex"
                },
                "hostSetting": {
                    "type": "string",
                    "description": "Link matchers only. Names one of this manifest's settings; the URI's host must equal its current value or the matcher does not fire."
                },
                "link": {
                    "type": "string",
                    "description": "The URL this match stands for."
                },
                "open": {
                    "type": "string",
                    "description": "An actions key, or one of open/copyLink/copyPath/reveal/showInPane. What the CLICK does instead of following link."
                },
                "suggested": {
                    "type": "boolean"
                },
                "description": {
                    "type": "string"
                }
            },
            "allOf": [
                {
                    "_comment": "A text matcher has no host to guard against.",
                    "if": {
                        "properties": {
                            "kind": {
                                "const": "text"
                            }
                        },
                        "required": [
                            "kind"
                        ]
                    },
                    "then": {
                        "not": {
                            "required": [
                                "hostSetting"
                            ]
                        }
                    }
                }
            ]
        },
        "step": {
            "type": "object",
            "required": [
                "id"
            ],
            "properties": {
                "id": {
                    "type": "string"
                },
                "type": {
                    "enum": [
                        "http",
                        "command"
                    ],
                    "default": "http"
                },
                "url": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "method": {
                    "type": "string"
                },
                "body": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "headers": {
                    "type": "object",
                    "additionalProperties": {
                        "type": "string"
                    }
                },
                "auth": {
                    "type": "object",
                    "required": [
                        "type"
                    ],
                    "properties": {
                        "type": {
                            "enum": [
                                "basic",
                                "bearer",
                                "header"
                            ]
                        },
                        "user": {
                            "type": "string",
                            "description": "A template string; {{...}} substitutions are expanded."
                        },
                        "password": {
                            "type": "string",
                            "description": "A template string; {{...}} substitutions are expanded."
                        },
                        "value": {
                            "type": "string",
                            "description": "A template string; {{...}} substitutions are expanded."
                        },
                        "header": {
                            "type": "string"
                        }
                    }
                },
                "commandLine": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "stdin": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "when": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "unless": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "optional": {
                    "type": "boolean"
                },
                "timeoutMs": {
                    "type": "number"
                },
                "allowUntrustedCertificate": {
                    "type": "boolean"
                }
            }
        },
        "display": {
            "type": "object",
            "properties": {
                "key": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                },
                "path": {
                    "type": "string",
                    "description": "An RFC 6901 pointer, optionally qualified by a step id. A negative index counts from the end."
                },
                "kind": {
                    "enum": [
                        "text",
                        "title",
                        "subtitle",
                        "badge",
                        "link",
                        "image",
                        "multiline"
                    ]
                },
                "placement": {
                    "enum": [
                        "details",
                        "header",
                        "status"
                    ],
                    "description": "Header fields remain visible across tabs; status is the header row next to state-changing actions."
                },
                "link": {
                    "type": "string",
                    "description": "URL template for this field. JSON pointer values are URL encoded."
                },
                "iconPath": {
                    "type": "string"
                },
                "colorPath": {
                    "type": "string"
                },
                "color": {
                    "type": "string"
                },
                "format": {
                    "enum": [
                        "relativeTime",
                        "date"
                    ]
                },
                "default": {
                    "type": "boolean"
                }
            }
        },
        "action": {
            "type": "object",
            "required": [
                "key"
            ],
            "properties": {
                "key": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                },
                "kind": {
                    "enum": [
                        "button",
                        "choice"
                    ],
                    "default": "button"
                },
                "optionsPath": {
                    "type": "string"
                },
                "optionIdPath": {
                    "type": "string"
                },
                "optionLabelPath": {
                    "type": "string"
                },
                "optionBadgePath": {
                    "type": "string"
                },
                "optionColorPath": {
                    "type": "string"
                },
                "optionTargetIdPath": {
                    "type": "string"
                },
                "optionFieldsPath": {
                    "type": "string"
                },
                "currentStatePath": {
                    "type": "string"
                },
                "method": {
                    "type": "string"
                },
                "url": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "body": {
                    "type": "string",
                    "description": "A template string; {{...}} substitutions are expanded."
                },
                "headers": {
                    "type": "object",
                    "additionalProperties": {
                        "type": "string"
                    }
                },
                "auth": {
                    "$ref": "#/$defs/step/properties/auth"
                },
                "timeoutMs": {
                    "type": "number"
                },
                "allowUntrustedCertificate": {
                    "type": "boolean"
                }
            }
        }
    }
}
