{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "master.json",
    "title": "Master Configuration",
    "description": "Schema for an Optimization Configuration JSON object",
    "type": "object",

    "properties": {

        "title": {
            "type": "string"
        },
        "description": {
            "type": "string"
        },
        "master": {
            "type": "boolean",
            "default": false
        },
        "weight": {
            "type": "number",
            "minimum": 1,
            "default": 1
        },

        "conditions": {
            "title": "Match on any condition in array.",
            "type": "array",
            "minItems": 1,
            "items": {
                "oneOf": [{
                    "$ref": "#/definitions/condition"
                }, {
                    "title": "Match on all conditions in array.",
                    "type": "array",
                    "minItems": 1,
                    "items": {
                        "$ref": "#/definitions/condition"
                    },
                    "uniqueItems": true
                }]
            },
            "uniqueItems": true
        },

        "html": {
            "$ref": "html.json#"
        },
        "css": {
            "$ref": "css.json#"
        },
        "js": {
            "$ref": "js.json#"
        },
        "pwa": {
            "$ref": "pwa.json#"
        },
        "csp": {
            "$ref": "csp.json#"
        },
        "fonts": {
            "$ref": "fonts.json#"
        },
        "headers": {
            "$ref": "headers.json#"
        },
        "http2": {
            "$ref": "http2.json#"
        },
        "timed-exec": {
            "$ref": "timed-exec.json#"
        },
        "cloudfront": {
            "$ref": "cloudfront.json#"
        },
        "google-cdn": {
            "$ref": "google-cdn.json#"
        },
        "cdn": {
            "title": "Content Delivery Network",
            "type": "object",
            "properties": {
                "enabled": {
                    "title": "Load assets via a CDN",
                    "type": "boolean",
                    "default": false
                },
                "url": {
                    "title": "CDN URL",
                    "type": "string",
                    "format": "uri",
                    "minLength": 1
                },
                "mask": {
                    "title": "CDN mask",
                    "type": "string"
                }
            },
            "additionalProperties": false,
            "required": ["enabled", "url"]
        }
    },
    "additionalProperties": false,
    "required": ["title", "weight"],

    "definitions": {

        "condition": {
            "title": "Condition configuration object",
            "type": "object",
            "properties": {
                "method": {
                    "title": "The method to call.",
                    "type": "string",
                    "pattern": "^([\\A-Za-z0-9_-]+::)?[A-Za-z0-9_-]+$"
                },
                "params": {
                    "title": "Parameters to apply to the method.",
                    "default": "null",
                    "oneOf": [{
                        "type": "null"
                    }, {
                        "type": "array",
                        "minItems": 1,
                        "items": {
                            "oneOf": [{
                                "type": "null"
                            }, {
                                "type": "boolean"
                            }, {
                                "type": "integer",
                                "minimum": 1
                            }, {
                                "type": "string",
                                "minLength": 1
                            }, {
                                "type": "array",
                                "minItems": 1,
                                "items": {
                                    "oneOf": [{
                                        "type": "null"
                                    }, {
                                        "type": "boolean"
                                    }, {
                                        "type": "integer",
                                        "minimum": 1
                                    }, {
                                        "type": "string",
                                        "minLength": 1
                                    }, {
                                        "type": "array",
                                        "minItems": 1,
                                        "items": {
                                            "oneOf": [{
                                                "type": "integer",
                                                "minimum": 1
                                            }, {
                                                "type": "string",
                                                "minLength": 1
                                            }]
                                        },
                                        "uniqueItems": true
                                    }]
                                }
                            }]
                        }
                    }]
                },
                "result": {
                    "title": "The method result to match.",
                    "oneOf": [{
                        "type": "boolean",
                        "default": true
                    }, {
                        "type": "integer"
                    }, {
                        "type": "string"
                    }, {
                        "title": "Match against an array.",
                        "type": "array",
                        "minItems": 1,
                        "items": {
                            "oneOf": [{
                                "type": "integer"
                            }, {
                                "type": "string"
                            }]
                        },
                        "uniqueItems": true
                    }]
                }
            },
            "required": ["method"]
        }
    }
}