{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://tonytools.win/schemas/dlge.schema.json",
    "type": "object",
    "title": "DialogEvent",
    "description": "A HMLanguages (TonyTools) DLGE JSON file.",
    "properties": {
        "$schema": {
            "type": "string",
            "format": "uri",
            "description": "The schema URL, if you're seeing this you probably already know what it is."
        },
        "hash": {
            "type": "string",
            "title": "Hash",
            "description": "The hash or path (if available) of the final output file."
        },
        "DITL": {
            "type": "string",
            "title": "DialogSoundTemplateList",
            "description": "The hash or path (if available) of the DITL file to use for soundtags."
        },
        "CLNG": {
            "type": "string",
            "title": "DialogCascadingLanguageDependencies",
            "description": "The hash or path (if available) of the CLNG file to use."
        },
        "langmap": {
            "type": "string",
            "title": "Language Map",
            "description": "Optional language map for if it differs from the default. Overrides any other language map."
        },
        "rootContainer": {
            "type": "object",
            "$ref": "#/$defs/Container",
            "title": "Root Container",
            "description": "The root container of the DLGE file.",
            "properties": {
                "type": {
                    "$ref": "#/$defs/Types"
                }
            },
            "required": ["type"],
            "unevaluatedProperties": false
        }
    },
    "required": ["hash", "DITL", "CLNG", "rootContainer"],
    "additionalProperties": false,
    "$defs": {
        "Types": {
            "enum": ["WavFile", "Random", "Switch", "Sequence"]
        },
        "Container": {
            "anyOf": [
                { "$ref": "#/$defs/WavFile" },
                { "$ref": "#/$defs/Random" },
                { "$ref": "#/$defs/Switch" },
                { "$ref": "#/$defs/Sequence" }
            ]
        },
        "WavFile": {
            "type": "object",
            "title": "WavFile Container",
            "description": "A WavFile container, defines a whole bunch of things.",
            "properties": {
                "type": {
                    "const": "WavFile",
                    "title": "Container Type",
                    "description": "The type of this container."
                },
                "wavName": {
                    "type": "string",
                    "title": "Wav Name",
                    "description": "The name of the wav file (or hash if unavailable) for this container. Must be lowercase.",
                    "pattern": "^[a-z0-9_]*$"
                },
                "soundtag": {
                    "type": "string",
                    "title": "Soundtag",
                    "description": "The soundtag name (or hash if unavailable) for this container."
                },
                "defaultWav": {
                    "type": ["string", "null"],
                    "title": "Default Wav",
                    "description": "The default wav hash or path (if available) for this container."
                },
                "defaultFfx": {
                    "type": ["string", "null"],
                    "title": "Default FaceFX Animation",
                    "description": "The default FaceFX animation hash or path (if available) for this container."
                },
                "languages": {
                    "type": "object",
                    "title": "Languages",
                    "description": "The languages for this container.",
                    "patternProperties": {
                        "^[a-z]{2}$": {
                            "oneOf": [
                                {
                                    "type": "string",
                                    "title": "Subtitle",
                                    "description": "The subtitle for this language."
                                },
                                {
                                    "type": "object",
                                    "title": "Custom Wav and FaceFX",
                                    "description": "The wav and FaceFX animation (plus optional subtitle) for this language.",
                                    "properties": {
                                        "wav": {
                                            "type": "string",
                                            "title": "Wav File",
                                            "description": "The wav hash or path (if available) for this language."
                                        },
                                        "ffx": {
                                            "type": "string",
                                            "title": "FaceFX File",
                                            "description": "The FaceFX animation hash or path (if available) for this language."
                                        },
                                        "subtitle": {
                                            "type": "string",
                                            "title": "Subtitle",
                                            "description": "The subtitle for this language."
                                        }
                                    },
                                    "required": ["wav", "ffx"],
                                    "additionalProperties": false
                                }
                            ]
                        }
                    },
                    "additionalProperties": false
                }
            },
            "required": ["type", "wavName", "soundtag", "defaultWav", "defaultFfx", "languages"]
        },
        "Random": {
            "type": "object",
            "title": "Random Container",
            "description": "A Random container, picks one of the wav files randomly with respect to their weight.",
            "properties": {
                "type": {
                    "const": "Random",
                    "title": "Container Type",
                    "description": "The type of this container."
                },
                "containers": {
                    "type": "array",
                    "title": "Containers",
                    "description": "The child containers for this container.",
                    "items": {
                        "allOf": [
                            {
                                "$ref": "#/$defs/WavFile"
                            },
                            {
                                "type": "object",
                                "properties": {
                                    "weight": {
                                        "type": ["number", "string"],
                                        "title": "Random Weight",
                                        "description": "How often this specific line should be chosen (0 to 1, inclusive). Strings will be parsed as hex."
                                    }
                                },
                                "required": ["weight"]
                            }
                        ],
                        "unevaluatedProperties": false
                    }
                }
            },
            "required": ["type", "containers"]
        },
        "Switch": {
            "type": "object",
            "title": "Switch Container",
            "description": "A Switch container, jumps to one of the child containers depending on the case value passed to it.",
            "properties": {
                "type": {
                    "const": "Switch",
                    "title": "Container Type",
                    "description": "The type of this container."
                },
                "switchKey": {
                    "type": "string",
                    "title": "Switch Key",
                    "description": "The key for this Switch container, this is what the game looks for."
                },
                "default": {
                    "type": "string",
                    "title": "Default",
                    "description": "The default case. This is used if a case is not explicitly handled."
                },
                "containers": {
                    "type": "array",
                    "title": "Containers",
                    "description": "The child containers for this container.",
                    "items": {
                        "allOf": [
                            {
                                "anyOf": [
                                    { "$ref": "#/$defs/WavFile" },
                                    { "$ref": "#/$defs/Random" }
                                ]
                            },
                            {
                                "type": "object",
                                "properties": {
                                    "cases": {
                                        "type": "array",
                                        "title": "Cases",
                                        "description": "Which cases this container should handle.",
                                        "items": { "type": "string" }
                                    }
                                },
                                "required": ["cases"]
                            }
                        ],
                        "unevaluatedProperties": false
                    }
                }
            },
            "required": ["type", "switchKey", "default", "containers"] 
        },
        "Sequence": {
            "type": "object",
            "title": "Sequence Container",
            "description": "A Sequence container, \"executes\" all child containers in order.",
            "properties": {
                "type": {
                    "const": "Sequence",
                    "title": "Container Type",
                    "description": "The type of this container."
                },
                "containers": {
                    "type": "array",
                    "title": "Containers",
                    "description": "The child containers for this container.",
                    "items": {
                        "anyOf": [
                            { "$ref": "#/$defs/WavFile" },
                            { "$ref": "#/$defs/Random" },
                            { "$ref": "#/$defs/Switch" }
                        ],
                        "unevaluatedProperties": false
                    }
                }
            },
            "required": ["type", "containers"]
        }
    }
}