{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "$id": "https://nextstrain.org/schemas/auspice/config/v2",
    "type": "object",
    "title": "Auspice config file to be supplied to `augur export v2`",
    "$comment": "This schema includes deprecated-but-handled-by-augur-export-v1 properties, but their schema definitions are somewhat incomplete",
    "additionalProperties": false,
    "required": [],
    "properties" : {
        "title": {
            "description": "Title to be displayed in auspice",
            "type" : "string"
        },
        "colorings": {
            "description": "Traits available as color-by options",
            "type": "array",
            "items": {
                "type": "object",
                "description": "Each object here is an individual coloring, which will populate the sidebar dropdown in auspice",
                "additionalProperties": false,
                "required": ["key"],
                "properties": {
                    "key": {
                        "description": "They key used to access the value of this coloring on each node",
                        "type": "string"
                    },
                    "title": {
                        "description": "Text to be displayed in the \"color by\" dropdown and legends",
                        "$comment": "string is parsed unchanged by Auspice",
                        "type": "string"
                    },
                    "type": {
                        "description": "Defines how the color scale should be constructed",
                        "$comment": "[augur export v2] will (try to) infer the type if this is not present",
                        "type": "string",
                        "enum": ["continuous", "temporal", "ordinal", "categorical", "boolean"]
                    },
                    "scale": {
                        "description": "Provided mapping between trait values & hex values. For continuous scales at least 2 items must be specified",
                        "$comment": "[auspice export v2] preferentially uses this over colors TSV",
                        "type": "array",
                        "items": {
                            "type": "array",
                            "items": [
                                {
                                    "type": ["string", "number"],
                                    "description": "For categorical/ordinal scales, this is the (string) value of the trait to associate with the colour. For continuous scales this is the (numeric) value to associate with the colour, and interpolation will be used to span the domain"
                                },
                                {"type": "string", "description": "color hex value", "pattern": "^#[0-9A-Fa-f]{6}$"}
                            ]
                        }
                    },
                    "legend": {
                        "description": "Specify the entries displayed in the legend. This can be used to restrict the entries in the legend for display without otherwise affecting the data viz",
                        "type": "array",
                        "items": {
                            "type": "object",
                            "required": ["value"],
                            "properties": {
                                "value": {
                                    "description": "value to associate with this legend entry. Used to determine colour. For non-continuous scales this also determines the matching between legend items and data.",
                                    "type": ["string", "number"],
                                    "$comment": "Continuous scales must use a numeric value. Other scales can use either."
                                },
                                "display": {
                                    "description": "Label to display in the legend. Optional - `value` will be used if this is not provided.",
                                    "type": ["string", "number"]
                                },
                                "bounds": {
                                    "description": "(for continuous scales only) provide the lower & upper bounds to match data to this legend entry. Bounds from different legend entries must not overlap. Matching is (a, b] - exclusive of the lower bound, inclusive of the upper.",
                                    "type": "array",
                                    "items": [
                                        {"type": "number", "description": "lower bound"},
                                        {"type": "number", "description": "upper bound"}
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "color_options": {
            "description": "DEPRECATED v1 syntax for defining colorings",
            "deprecated": true,
            "type": "object"
        },
        "geo_resolutions": {
            "description": "Traits to be interpreted as 'geo resolution' options -- i.e. associated with lat/longs & made points on the map",
            "$comment": "Note that array entries can be different structures & you can mix & match",
            "type": "array",
            "uniqueItems": true,
            "minItems": 1,
            "items": {
                "oneOf": [
                    {
                        "type": "object",
                        "description": "An indiviual geo resolution",
                        "additionalProperties": false,
                        "required": ["key"],
                        "properties": {
                            "key": {
                                "type": "string",
                                "description": "Trait key - must be specified on nodes (e.g. 'country')"
                            },
                            "title": {
                                "type": "string",
                                "description": "The title to display in the geo resolution dropdown. Optional -- if not provided then `key` will be used."
                            }
                        }
                    },
                    {
                        "type": "string",
                        "description": "An indiviual geo resolution key"
                    }
                ]
            }
        },
        "geo": {
            "description": "DEPRECATED v1 syntax for defining geo_resolutions",
            "deprecated": true,
            "type": "array"
        },
        "maintainers": {
            "description": "Who maintains this dataset?",
            "$comment": "order similar to a publication",
            "type": "array",
            "uniqueItems": true,
            "minItems": 1,
            "items": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "url": {"type": "string"}
                },
                "required": ["name"]
            }
        },
        "maintainer": {
            "description": "DEPRECATED v1 syntax for defining maintainers (but you could only define one!)",
            "deprecated": true,
            "type": "array"
        },
        "build_url": {
          "description": "URL with instructions to reproduce build, usually expected to be a GitHub repo URL",
          "$comment": "Auspice displays this at the top of the page as part of a byline",
          "type": "string"
        },
        "filters": {
          "description": "These appear as filters in the footer of Auspice (which populates the displayed values based upon the tree)",
          "$comment": "These values must be present as keys on a tree node -> trait",
          "type": "array",
          "uniqueItems": true,
          "items": {"type": "string"}
        },
        "display_defaults": {
            "description": "Set the defaults for certain display options in Auspice. All are optional.",
            "$comment": "Anything able to be encoded in the auspice URL should eventually be an option here, so this will expand over time",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "map_triplicate": {
                    "type": "boolean"
                },
                "geo_resolution": {
                    "$comment": "The value here must be present in geo_resolutions (see above)",
                    "type": "string"
                },
                "color_by": {
                    "$comment": "The value here must be present in the colorings (see above)",
                    "type": "string"
                },
                "distance_measure": {
                    "type": "string",
                    "enum": ["num_date", "div"]
                },
                "layout": {
                    "type": "string",
                    "enum": ["rect", "radial", "unrooted", "clock"]
                },
                "branch_label": {
                    "description": "What branch label should be displayed by default, or 'none' to hide labels by default.",
                    "$comment": "Should be a key present in the per-node branch_attrs.labels object of the exported JSON; pattern is from the schema for that object",
                    "type": "string",
                    "pattern": "^(none|[a-zA-Z0-9]+)$"
                },
                "tip_label": {
                  "description": "What tip label should be displayed by default, or 'none' to hide labels by default.",
                  "$comment": "Should be a key present in (at least some) node_attrs",
                  "type": "string"
              },
                "transmission_lines": {
                    "$comment": "Transmission lines depend on the geo_resolution being defined for internal nodes",
                    "type": "boolean"
                },
                "language": {
                    "type": "string",
                    "minLength": 1,
                    "description": "A BCP 47 language tag specifying the default language in which to display Auspice's interface (if supported)"
                },
                "sidebar": {
                    "type": "string",
                    "enum": ["open", "closed"]
                },
                "panels": {
                    "type": "array",
                    "description": "Panels which start toggled on (default is for all available to be shown)",
                    "minItems": 1,
                    "items": {
                        "type": "string",
                        "enum": ["tree", "map", "frequencies", "entropy"]
                    }
                }
            }
        },
        "defaults": {
            "description": "DEPRECATED v1 syntax for defining auspice view defaults",
            "deprecated": true,
            "type": "object"
        },
        "updated": {
            "description": "DEPRECATED v1 (or older) syntax for defining when the build was updated",
            "$comment": "unused in augur v6",
            "deprecated": true,
            "type": "string"
        },
        "panels": {
            "description": "The panels available for display",
            "$comment": "The frequencies & measurements panel will only be available if defined here (and if their sidecar files are available)",
            "type": "array",
            "minItems": 1,
            "items": {
                "type": "string",
                "enum": ["tree", "map", "frequencies", "entropy", "measurements"]
            }
        },
        "vaccine_choices": {
            "type": "object",
            "description": "UNUSED v1 syntax for defining vaccine choices",
            "$comment": "This is unused in `augur export v2` which gets vaccine info vis a node-data JSON file. It remains in the schema so that v1 config files can be used by `augur export v2`"
        },
        "data_provenance": {
            "description": "Specify provenance of data included in this analysis",
            "type": "array",
            "minItems": 1,
            "items": {
                "type": "object",
                "description": "An individual data source",
                "additionalProperties": false,
                "required": ["name"],
                "properties": {
                    "name": {
                        "description": "Name of the data source",
                        "type": "string"
                    },
                    "url": {
                        "description": "URL to use in link to data source",
                        "type": "string"
                    }
                }
            }
        },
        "metadata_columns": {
            "description": "Metadata TSV columns to export in addition to columns provided as colorings.",
            "$comment": "These columns will not be used as coloring options in Auspice but will be visible in the tree.",
            "type": "array",
            "uniqueItems": true,
            "items": {"type": "string"}
        },
        "extensions": {
            "description": "Data to be passed through to the the resulting dataset JSON",
            "$comment": "Any type is accepted"
        }
    }
}
