{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "definitions": {
        "string_limit": {
            "maxLength": 1000
        },
        "specific_slicer_settings": {
            "type": "object",
            "properties": {
                "profile_path": {
                    "type": "string",
                    "description": "The path to the profile that should be used for this filament",
                    "$ref": "#/definitions/string_limit"
                },
                "overrides": {
                    "type": "object",
                    "description": "Key-value pairs for settings that should be overridden for this filament"
                },
                "id": {
                    "type": "string",
                    "description": "The slicer-native identifier for this filament profile (e.g. GFB00, FFF02)",
                    "$ref": "#/definitions/string_limit"
                },
                "generic_id": {
                    "type": "string",
                    "description": "Fallback generic slicer profile ID for this material type (e.g. GFL99 for Generic PLA)",
                    "$ref": "#/definitions/string_limit"
                }
            },
            "required": [
                "profile_path"
            ]
        },
        "slicer_settings": {
            "type": "object",
            "properties": {
                "generic": {
                    "type": "object",
                    "description": "Generic options that will automatically be mapped to the correct config definition for each slicer. Slicer specific settings are applied first, then these are applied on top.",
                    "properties": {
                        "first_layer_bed_temp": {
                            "type": "integer"
                        },
                        "first_layer_nozzle_temp": {
                            "type": "integer"
                        },
                        "bed_temp": {
                            "type": "integer"
                        },
                        "nozzle_temp": {
                            "type": "integer"
                        }
                    }
                },
                "prusaslicer": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "bambustudio": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "orcaslicer": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "cura": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "superslicer": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "elegooslicer": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "crealityprint": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "anycubicslicer": {
                    "$ref": "#/definitions/specific_slicer_settings"
                },
                "kirimoto": {
                    "$ref": "#/definitions/specific_slicer_settings"
                }
            },
            "additionalProperties": false
        }
    },
    "properties": {
        "$schema": {
            "type": "string",
            "$ref": "#/definitions/string_limit"
        },
        "material": {
            "type": "string",
            "description": "The material type of the filament",
            "$ref": "#/definitions/string_limit"
        },
        "default_slicer_settings": {
            "$ref": "#/definitions/slicer_settings",
            "description": "The default slicer settings that should be used for this type of filament material. This will be used in any case where a filament does not specify its own \"slicer_settings\""
        },
        "filaments": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "description": "The manufacture's name for this filament",
                        "$ref": "#/definitions/string_limit"
                    },
                    "diameter_tolerance": {
                        "type": "number",
                        "description": "The diameter tolerance of the filament (in mm)"
                    },
                    "density": {
                        "type": "number",
                        "description": "The density of the filament (in g/cm\u00b3)",
                        "default": 1.24
                    },
                    "data_sheet_url": {
                        "type": "string",
                        "description": "A link to the data sheet for this filament",
                        "$ref": "#/definitions/string_limit"
                    },
                    "safety_sheet_url": {
                        "type": "string",
                        "description": "A link to the safety sheet for this filament",
                        "$ref": "#/definitions/string_limit"
                    },
                    "slicer_settings": {
                        "$ref": "#/definitions/slicer_settings",
                        "description": "The slicer settings that should be used for this filament. This will override what is set in \"default_slicer_settings\""
                    },
                    "variants": {
                        "type": "array",
                        "description": "Variants are the same filament, but in a different color or finish",
                        "items": {
                            "type": "object",
                            "properties": {
                                "color_name": {
                                    "type": "string",
                                    "description": "The manufacturer's name for this filament color",
                                    "$ref": "#/definitions/string_limit"
                                },
                                "color_hex": {
                                    "type": [
                                        "string",
                                        "array"
                                    ],
                                    "items": {
                                        "type": "string",
                                        "pattern": "^#?[a-fA-F0-9]{6}$"
                                    },
                                    "pattern": "^#?[a-fA-F0-9]{6}$",
                                    "description": "The hex color code for this filament"
                                },
                                "traits": {
                                    "type": "object",
                                    "properties": {
                                        "translucent": {
                                            "type": "boolean",
                                            "description": "Indicates that the filament is translucent"
                                        },
                                        "glow": {
                                            "type": "boolean",
                                            "description": "Indicates that the filament glows in the dark"
                                        },
                                        "matte": {
                                            "type": "boolean",
                                            "description": "Indicates that the filament has a matte finish"
                                        },
                                        "recycled": {
                                            "type": "boolean",
                                            "description": "Indicates that the filament was made of recycled materials"
                                        },
                                        "recyclable": {
                                            "type": "boolean",
                                            "description": "Indicates that the filament can be recycled"
                                        },
                                        "biodegradable": {
                                            "type": "boolean",
                                            "description": "Indicates if the filament will biodegrade"
                                        }
                                    },
                                    "additionalProperties": false
                                },
                                "sizes": {
                                    "type": "array",
                                    "items": {
                                        "type": "object",
                                        "properties": {
                                            "filament_weight": {
                                                "type": "number",
                                                "description": "The weight of the filament alone (in grams)",
                                                "default": 1000
                                            },
                                            "empty_spool_weight": {
                                                "type": "number",
                                                "description": "The weight of a spool with no filament (in grams)"
                                            },
                                            "diameter": {
                                                "type": "number",
                                                "description": "The diameter of the filament (in mm)",
                                                "default": 1.75
                                            },
                                            "spool_refill": {
                                                "type": "boolean",
                                                "description": "Indicates if this is a refill for a reusable spool",
                                                "default": false
                                            },
                                            "sku": {
                                                "type": "string",
                                                "$ref": "#/definitions/string_limit"
                                            },
                                            "gtin": {
                                                "type": "string",
                                                "description": "Global Trade Item Number (GTIN-12 or GTIN-13)"
                                            },
                                            "ean": {
                                                "type": "string",
                                                "$ref": "#/definitions/string_limit",
                                                "description": "(deprecated) legacy EAN alias for gtin"
                                            },
                                            "purchase_links": {
                                                "type": "array",
                                                "description": "A list of places to purchase this filament",
                                                "$comment": "The key for the pattern should be the name of the store",
                                                "items": {
                                                    "type": "object",
                                                    "properties": {
                                                        "store_id": {
                                                            "type": "string",
                                                            "$ref": "#/definitions/string_limit"
                                                        },
                                                        "url": {
                                                            "type": "string",
                                                            "$ref": "#/definitions/string_limit"
                                                        },
                                                        "ships_from": {
                                                            "type": [
                                                                "array",
                                                                "string"
                                                            ],
                                                            "description": "A list of locations the shop ships from. Defining this here will override the definition from the shop.",
                                                            "items": {
                                                                "type": "string",
                                                                "$ref": "#/definitions/string_limit"
                                                            },
                                                            "$ref": "#/definitions/string_limit"
                                                        },
                                                        "ships_to": {
                                                            "type": [
                                                                "array",
                                                                "string"
                                                            ],
                                                            "description": "A list of locations the shop ships to. Defining this here will override the definition from the shop.",
                                                            "items": {
                                                                "type": "string",
                                                                "$ref": "#/definitions/string_limit"
                                                            },
                                                            "$ref": "#/definitions/string_limit"
                                                        }
                                                    },
                                                    "required": [
                                                        "url"
                                                    ]
                                                }
                                            }
                                        },
                                        "additionalProperties": false,
                                        "required": [
                                            "filament_weight",
                                            "diameter"
                                        ]
                                    },
                                    "minItems": 1
                                }
                            },
                            "additionalProperties": false,
                            "required": [
                                "color_name",
                                "color_hex",
                                "sizes"
                            ]
                        },
                        "minItems": 1
                    }
                },
                "additionalProperties": false,
                "required": [
                    "name",
                    "density",
                    "variants"
                ]
            },
            "minItems": 1
        }
    },
    "additionalProperties": false,
    "required": [
        "material",
        "filaments"
    ]
}