{
    "id": "http://www.gandhi.io/schema/cycle",
    "$schema": "http://json-schema.org/draft-04/schema",
    "required": [
        "id",
        "title"
    ],
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "id": {
            "type": "string"
        },
        "title": {
            "type": "string"
        },
        "description": {
            "type": "string",
            "default": ""
        },
        "options": {
            "type": "object",
            "default": {
                "open": true,
                "close": false
            },
            "properties": {
                "open": {
                    "type": [
                        "boolean",
                        "number"
                    ],
                    "default": true
                },
                "close": {
                    "type": [
                        "boolean",
                        "number"
                    ],
                    "default": false
                }
            }
        },
        "instructions": {
            "type": "string",
            "default": ""
        },
        "triggers": {
            "type": "object",
            "default": {
                "open": {
                    "id": "open",
                    "title": "Application Opens",
                    "conditions": [
                        [
                            {
                                "name": "date",
                                "invert": false,
                                "options": {
                                    "timestamp": 0
                                }
                            }
                        ]
                    ],
                    "actions": []
                },
                "close": {
                    "id": "close",
                    "title": "Application Closes",
                    "conditions": [
                        [
                            {
                                "name": "date",
                                "invert": false,
                                "options": {
                                    "timestamp": 0
                                }
                            }
                        ]
                    ],
                    "actions": []
                }
            },
            "additionalProperties": {
                "$ref": "#/definitions/trigger"
            }
        },
        "defaults": {
            "type": "object",
            "default": {
                "role_id": "applicant",
                "status_id": "active"
            },
            "properties": {
                "role_id": {
                    "type": "string",
                    "default": "applicant"
                },
                "status_id": {
                    "type": "string",
                    "default": "active"
                }
            }
        },
        "stages": {
            "type": "object",
            "default": {
                "start": {
                    "id": "start",
                    "title": "Start",
                    "description": "Start your application!",
                    "visible": {
                        "applicant": {
                            "open": [
                                "open"
                            ],
                            "close": false
                        }
                    },
                    "component": {
                        "name": "start",
                        "options": {},
                        "permissions": {
                            "write": {
                                "applicant": true
                            }
                        }
                    },
                    "order": 0
                }
            },
            "additionalProperties": {
                "$ref": "#/definitions/stage"
            }
        },
        "roles": {
            "type": "object",
            "default": {
                "applicant": {
                    "id": "applicant",
                    "title": "Applicant",
                    "visible": {
                        "applicant": true
                    },
                    "assignable": {
                        "applicant": true
                    }
                }
            },
            "additionalProperties": {
                "$ref": "#/definitions/role"
            }
        },
        "status_id": {
            "type": "string",
            "default": "draft",
            "enum": [
                "draft",
                "active",
                "archived"
            ]
        },
        "statuses": {
            "type": "object",
            "default": {
                "active": {
                    "id": "active",
                    "title": "Active"
                },
                "archived": {
                    "id": "archived",
                    "title": "Archived"
                }
            },
            "additionalProperties": {
                "$ref": "#/definitions/status"
            }
        },
        "assignments": {
            "type": "object",
            "default": {},
            "additionalProperties": {
                "$ref": "#/definitions/assignment"
            }
        },
        "invitations": {
            "type": "object",
            "default": {},
            "additionalProperties": {
                "$ref": "#/definitions/invitation"
            }
        },
        "updated": {
            "type": "number"
        },
        "created": {
            "type": "number"
        },
        "permissions": {
            "type": "object",
            "required": [
                "project:read",
                "project:create",
                "project:update",
                "project:delete",
                "project/assignments:read",
                "project/assignments:write",
                "project/invitations:read",
                "project/invitations:write",
                "project/contents:read",
                "project/contents:write"
            ],
            "properties": {
                "project:read": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project:create": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project:update": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project:delete": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project/assignments:read": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project/assignments:write": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project/contents:read": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project/contents:write": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project/invitations:read": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "project/invitations:write": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                }
            },
            "default": {
                "project:read": {
                    "applicant": true
                },
                "project:create": {
                    "applicant": true
                },
                "project:update": {
                    "applicant": true
                },
                "project:delete": {
                    "applicant": false
                },
                "project/assignments:read": {
                    "applicant": true
                },
                "project/assignments:write": {
                    "applicant": true
                },
                "project/contents:read": {
                    "applicant": true
                },
                "project/contents:write": {
                    "applicant": true
                },
                "project/invitations:read": {
                    "applicant": true
                },
                "project/invitations:write": {
                    "applicant": true
                }
            }
        }
    },
    "definitions": {
        "assignment": {
            "type": "object",
            "additionalProperties": false,
            "required": [
                "id",
                "role_id"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "constant": {
                        "$data": "0"
                    }
                },
                "role_id": {
                    "type": "string"
                },
                "invitation_id": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "default": null
                }
            }
        },
        "invitation": {
            "type": "object",
            "additionalProperties": false,
            "required": [
                "id",
                "role_id"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "constant": {
                        "$data": "0"
                    }
                },
                "role_id": {
                    "type": "string"
                },
                "name": {
                    "type": "string",
                    "default": ""
                },
                "email": {
                    "anyOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "null"
                        }
                    ],
                    "default": null
                },
                "message": {
                    "anyOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "null"
                        }
                    ],
                    "default": null
                }
            }
        },
        "permission": {
            "type": "object",
            "default": {},
            "additionalProperties": {
                "anyOf": [
                    {
                        "type": "object",
                        "additionalProperties": false,
                        "default": {
                            "open": true,
                            "close": false
                        },
                        "required": [
                            "open",
                            "close"
                        ],
                        "properties": {
                            "open": {
                                "default": true,
                                "anyOf": [
                                    {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    },
                                    {
                                        "type": "boolean"
                                    }
                                ]
                            },
                            "close": {
                                "default": false,
                                "anyOf": [
                                    {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    },
                                    {
                                        "type": "boolean"
                                    }
                                ]
                            }
                        }
                    },
                    {
                        "type": "boolean"
                    }
                ]
            }
        },
        "role": {
            "type": "object",
            "required": [
                "id",
                "title",
                "visible",
                "assignable"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "type": "string",
                    "constant": {
                        "$data": "0"
                    }
                },
                "title": {
                    "type": "string"
                },
                "visible": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "assignable": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                }
            }
        },
        "stage": {
            "type": "object",
            "required": [
                "id",
                "title",
                "component"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "type": "string",
                    "constant": {
                        "$data": "0"
                    }
                },
                "title": {
                    "type": "string"
                },
                "description": {
                    "type": "string",
                    "default": ""
                },
                "visible": {
                    "$ref": "#/definitions/permission",
                    "default": {}
                },
                "component": {
                    "type": "object",
                    "required": [
                        "name"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "name": {
                            "type": "string"
                        },
                        "options": {
                            "type": "object",
                            "default": {},
                            "additionalProperties": true
                        },
                        "permissions": {
                            "type": "object",
                            "default": {},
                            "additionalProperties": {
                                "$ref": "#/definitions/permission"
                            }
                        },
                        "manifest": {
                            "type": "object",
                            "default": {},
                            "additionalProperties": {
                                "type": "object",
                                "required": [
                                    "id",
                                    "title",
                                    "schema"
                                ],
                                "properties": {
                                    "id": {
                                        "type": "string",
                                        "constant": {
                                            "$data": "0"
                                        }
                                    },
                                    "title": {
                                        "type": "string"
                                    },
                                    "schema": {
                                        "type": "object"
                                    },
                                    "template": {
                                        "type": "string",
                                        "default": "{{ value }}"
                                    },
                                    "options": {
                                        "type": "object",
                                        "default": {}
                                    }
                                }
                            }
                        }
                    }
                },
                "order": {
                    "type": "number",
                    "default": 0
                }
            }
        },
        "status": {
            "type": "object",
            "required": [
                "id",
                "title"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "type": "string",
                    "constant": {
                        "$data": "0"
                    }
                },
                "title": {
                    "type": "string"
                }
            }
        },
        "trigger": {
            "type": "object",
            "required": [
                "id",
                "title"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "type": "string",
                    "constant": {
                        "$data": "0"
                    }
                },
                "title": {
                    "type": "string"
                },
                "description": {
                    "type": "string",
                    "default": ""
                },
                "conditions": {
                    "type": "array",
                    "default": [],
                    "items": {
                        "type": "array",
                        "minItems": 1,
                        "items": {
                            "anyOf": [
                                {
                                    "type": "object",
                                    "required": [
                                        "name",
                                        "options"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "name": {
                                            "type": "string",
                                            "constant": "date"
                                        },
                                        "invert": {
                                            "type": "boolean",
                                            "default": false
                                        },
                                        "options": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "required": [
                                                "timestamp"
                                            ],
                                            "properties": {
                                                "timestamp": {
                                                    "type": "number"
                                                }
                                            }
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "required": [
                                        "name",
                                        "options"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "name": {
                                            "type": "string",
                                            "constant": "project_status"
                                        },
                                        "invert": {
                                            "type": "boolean",
                                            "default": false
                                        },
                                        "options": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "required": [
                                                "status_id"
                                            ],
                                            "properties": {
                                                "status_id": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "required": [
                                        "name",
                                        "options"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "name": {
                                            "type": "string",
                                            "constant": "content_status"
                                        },
                                        "invert": {
                                            "type": "boolean",
                                            "default": false
                                        },
                                        "options": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "required": [
                                                "status_id",
                                                "content_id"
                                            ],
                                            "properties": {
                                                "status_id": {
                                                    "type": "string"
                                                },
                                                "content_id": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "required": [
                                        "name",
                                        "options"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "name": {
                                            "type": "string",
                                            "constant": "export"
                                        },
                                        "invert": {
                                            "type": "boolean",
                                            "default": false
                                        },
                                        "options": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "required": [
                                                "content_id",
                                                "export_id",
                                                "value"
                                            ],
                                            "properties": {
                                                "content_id": {
                                                    "type": "string"
                                                },
                                                "export_id": {
                                                    "type": "string"
                                                },
                                                "op": {
                                                    "type": "string"
                                                },
                                                "value": {}
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                },
                "actions": {
                    "type": "array",
                    "default": [],
                    "items": {
                        "type": "object",
                        "required": [
                            "name"
                        ],
                        "additionalProperties": false,
                        "properties": {
                            "name": {
                                "type": "string"
                            },
                            "options": {
                                "type": "object",
                                "additionalProperties": true,
                                "default": {}
                            }
                        }
                    }
                }
            }
        }
    }
}