{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "required": [
        "_elements"
    ],
    "properties": {
        "_attributes": {
            "type": "object",
            "required": [
                "extracted"
            ],
            "properties": {
                "extracted": {
                    "type": "boolean"
                }
            }
        },
        "_elements": {
            "type": "array",
            "items": {
                "anyOf": [
                    {
                        "$ref": "#/definitions/file"
                    },
                    {
                        "$ref": "#/definitions/file_remote_dir"
                    }
                ]
            }
        }
    },
    "definitions": {
        "file_common": {
            "type": "object",
            "required": [
                "name",
                "type"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "file": {
            "allOf": [
                {
                    "$ref": "#/definitions/file_common"
                },
                {
                    "properties": {
                        "user": {
                            "type": "string",
                            "minLength": 1
                        },
                        "group": {
                            "type": "string",
                            "minLength": 1
                        }
                    },
                    "oneOf": [
                        {
                            "$ref": "#/definitions/file_file"
                        },
                        {
                            "$ref": "#/definitions/file_dir"
                        },
                        {
                            "$ref": "#/definitions/file_link"
                        }
                    ]
                }
            ]
        },
        "file_file": {
            "properties": {
                "type": {
                    "enum": [
                        "file"
                    ]
                },
                "size": {
                    "type": "integer",
                    "minimum": 0
                },
                "mode": {
                    "type": "string",
                    "pattern": "^[0-7]{3,4}$"
                }
            }
        },
        "file_dir": {
            "properties": {
                "type": {
                    "enum": [
                        "dir"
                    ]
                },
                "size": {
                    "type": "integer",
                    "minimum": 0
                },
                "mode": {
                    "type": "string",
                    "pattern": "^[0-4]?[0-7]{3}$"
                },
                "files": {
                    "type": "integer",
                    "minimum": 0
                }
            }
        },
        "file_link": {
            "properties": {
                "type": {
                    "enum": [
                        "link"
                    ]
                }
            }
        },
        "file_remote_dir": {
            "allOf": [
                {
                    "$ref": "#/definitions/file_common"
                },
                {
                    "properties": {
                        "type": {
                            "enum": [
                                "remote_dir"
                            ]
                        }
                    }
                }
            ]
        }
    }
}