{
    "title": "Smalldb Flupdo State Machine",
    "type": "object",
    "required": [
        "class",
        "auth_resource",
        "table"
    ],
    "properties": {
        "_": {
            "description": "Token to stop PHP from interpreting the rest of the file. Ignored by Smalldb.",
            "type": "string",
            "pattern": "^<\\?php printf\\('_%c%c}%c',34,10,10\\);__halt_compiler\\(\\);\\?>$",
            "_annotation": "AbstractMachine"
        },
        "class": {
            "description": "Interpreted by JsonDirBackend. PHP class name of transitions implementation.",
            "type": "string",
            "pattern": "^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(\\\\[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*$",
            "_annotation": "JsonDirBackend"
        },
        "include": {
            "description": "Interpreted by JsonDirBackend only. List of files to include and merge with this JSON file.",
            "type": "array",
            "_annotation": "JsonDirBackend",
            "items": {
                "description": "File name of the file to include or object containing the filename and additional options.",
                "type": [
                    "string",
                    "object"
                ],
                "properties": {
                    "file": {
                        "description": "File name of the file to include.",
                        "type": "string",
                        "_annotation": "JsonDirBackend"
                    }
                },
                "additionalProperties": {
                    "description": "Options passed to dedicated reader.",
                    "_annotation": "JsonDirBackend"
                },
                "_annotation": "JsonDirBackend"
            }
        },
        "state_diagram_extras": {
            "description": "List of additional fragments of state diagram.",
            "type": "array",
            "items": {
                "description": "Dot source code to be added just before the end of the state diagram..",
                "type": "string",
                "_annotation": "AbstractMachine"
            },
            "_annotation": "AbstractMachine"
        },
        "properties": {
            "description": "State machine properties. If not defined (or empty object), the properties are automatically detected from the database columns (including is_pk).",
            "type": "object",
            "additionalProperties": {
                "description": "State machine property definition",
                "type": "object",
                "properties": {
                    "label": {
                        "description": "Name of the property (human readable).",
                        "type": "string",
                        "_annotation": false
                    },
                    "type": {
                        "description": "Type of the property (not interpreted by the state machine; autodetection uses column types provided by the database).",
                        "type": "string",
                        "_annotation": false
                    },
                    "is_pk": {
                        "description": "Flag whether the property is a primary key. Compound primary keys must have properties defined in correct order.",
                        "type": "bool",
                        "default": false,
                        "_annotation": false
                    },
                    "components": {
                        "description": "Property is composed from these database columns. Data are loaded into a key-value map (array); the components are the keys, the database columns are the values.",
                        "type": [
                            "null",
                            "object"
                        ],
                        "additionalProperties": {
                            "description": "Name of the database column.",
                            "type": "string",
                            "_annotation": false
                        },
                        "default": null,
                        "_annotation": false
                    },
                    "column_encoding": {
                        "description": "Data are encoded before storing in the database and decoded after loading from the database using this encoding. This allows storing complex data in a single text/blob column (as long as the database does not need to understand this column).",
                        "type": [
                            "null",
                            "string"
                        ],
                        "enum": [
                            null,
                            "json"
                        ],
                        "default": null,
                        "_annotation": false
                    }
                },
                "_annotation": "AbstractMachine"
            },
            "_annotation": false
        },
        "states": {
            "description": "State machine states",
            "type": "object",
            "additionalProperties": {
                "description": "State of the state machine",
                "type": "object",
                "properties": {
                    "color": {
                        "description": "Color of the state in the state diagram (fillcolor). Visual effect only.",
                        "type": "string",
                        "pattern": "^#[0-9A-Fa-f]{6}$",
                        "_annotation": "AbstractMachine"
                    },
                    "group": {
                        "description": "Name of a group (subgraph) in the state diagram to which the state belongs. Visual effect only. See state_groups.",
                        "type": "string",
                        "_annotation": "AbstractMachine"
                    }
                },
                "_annotation": "AbstractMachine"
            },
            "_annotation": "AbstractMachine"
        },
        "state_groups": {
            "description": "Groups of states in the state machine diagram. Visual effect only.",
            "type": "object",
            "additionalProperties": {
                "description": "Group of states in the state machine diagram.",
                "type": "object",
                "required": [
                    "label"
                ],
                "additionalProperties": false,
                "properties": {
                    "label": {
                        "description": "Label of the group.",
                        "type": "string",
                        "_annotation": "AbstractMachine"
                    },
                    "color": {
                        "description": "Color of the group (border and label).",
                        "type": "string",
                        "pattern": "^#[0-9A-Fa-f]{6}$",
                        "_annotation": "AbstractMachine"
                    },
                    "state_groups": {
                        "description": "Recursively nested state groups (same as parent state_groups).",
                        "type": "object",
                        "_annotation": "AbstractMachine"
                    }
                },
                "_annotation": "AbstractMachine"
            },
            "_annotation": "AbstractMachine"
        },
        "actions": {
            "description": "State machine actions (groups of transitions of the same name).",
            "type": "object",
            "additionalProperties": {
                "description": "State machine action.",
                "type": "object",
                "properties": {
                    "transitions": {
                        "description": "Transitions of the action",
                        "type": "object",
                        "additionalProperties": {
                            "description": "Starting state of the transition.",
                            "type": "object",
                            "properties": {
                                "targets": {
                                    "description": "List of possible target states of the transition starting from this state.",
                                    "type": "array",
                                    "items": {
                                        "type": "string",
                                        "_annotation": "AbstractMachine"
                                    },
                                    "_annotation": "AbstractMachine"
                                }
                            },
                            "additionalProperties": {
                                "type": "object",
                                "description": "All properties are merged with action's properties; transition's properties have precedence.",
                                "_annotation": "AbstractMachine"
                            },
                            "_annotation": "AbstractMachine"
                        },
                        "_annotation": "AbstractMachine"
                    },
                    "method": {
                        "description": "Name of PHP method which implements the transition.",
                        "type": "string",
                        "pattern": "^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$",
                        "_annotation": "AbstractMachine"
                    },
                    "args": {
                        "description": "Additional arguments prefixed to transition arguments when calling the method.",
                        "type": "array",
                        "_annotation": "AbstractMachine"
                    },
                    "pre_check_methods": {
                        "description": "Methods to call before the transition is invoked. All of these methods must not return false otherwise the transition is aborted.",
                        "type": "array",
                        "items": {
                            "type": "string",
                            "pattern": "^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$",
                            "_annotation": "AbstractMachine"
                        },
                        "_annotation": "AbstractMachine"
                    },
                    "returns": {
                        "description": "Semantics of return value of the method.",
                        "type": [
                            "string",
                            "null"
                        ],
                        "_annotation": "AbstractMachine"
                    },
                    "post_transition_methods": {
                        "description": "Methods to call after the transition is invoked.",
                        "type": "array",
                        "items": {
                            "type": "string",
                            "pattern": "^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$",
                            "_annotation": "AbstractMachine"
                        },
                        "_annotation": "AbstractMachine"
                    },
                    "color": {
                        "description": "Color of the arrow in the state diagram.",
                        "type": "string",
                        "pattern": "^#[0-9A-Fa-f]{6}$",
                        "_annotation": "AbstractMachine"
                    },
                    "weight": {
                        "description": "Weight of the arrow in the state diagram (heavier arrows are rendered shorter).",
                        "type": "number",
                        "_annotation": "AbstractMachine"
                    },
                    "access_policy": {
                        "description": "Name of required access policy, see access_policies.",
                        "type": "string",
                        "_annotation": "AbstractMachine"
                    }
                },
                "_annotation": "AbstractMachine"
            },
            "_annotation": "AbstractMachine"
        },
        "access_policies": {
            "description": "Access policies",
            "type": "object",
            "additionalProperties": {
                "description": "Access policy",
                "type": "object",
                "properties": {
                    "arrow_tail": {
                        "description": "Shape of arrow tail in the state diagram. Visual effect only. See http://www.graphviz.org/content/arrow-shapes.",
                        "type": "string",
                        "pattern": "^((|l|r|o|ol|or)box|(|l|r)crow|(l|r|o|ol|or)diamond|(|o)dot|(|l|r|o|ol|or)inv|none|(|l|r|o|ol|or)normal|(|l|r)tee|(|l|e)vee|(|l|r|i|li|ri)curve){1,4}$",
                        "_annotation": "AbstractMachine"
                    },
                    "type": {
                        "description": "Type of the policy (algorithm).",
                        "type": "string",
                        "required": true,
                        "enum": [
                            "anyone",
                            "nobody",
                            "anonymous",
                            "user",
                            "owner",
                            "role",
                            "condition",
                            "user_relation"
                        ],
                        "_annotation": false
                    },
                    "owner_property": {
                        "description": "State machine property (scalar ID) which defines owner of this state machine instance. Used by 'owner' policy type.",
                        "type": "string",
                        "_annotation": false
                    },
                    "session_state": {
                        "description": "Required state of the session machine (IAuth). Used by 'owner' policy type. If not set, the session state is not checked.",
                        "type": "string",
                        "_annotation": false
                    },
                    "required_role": {
                        "description": "Required user role. Used by 'role' policy type.",
                        "type": "string",
                        "_annotation": false
                    },
                    "sql_select": {
                        "description": "SQL expression to retrieve the checked value from the database. It will be mixed into the SQL select or where clause when reading state machine properties. Used by 'condition' and 'user_relation' policy types. The policy allows access when this expression is not null or when equal to 'required_role' (if set). When used with 'user_relation' policy type, it accepts one parameter (positional placeholder '?') which provides user's ID.",
                        "type": "string",
                        "_annotation": false
                    },
                    "required_value": {
                        "description": "Value required to be equal to the value of 'sql_select'. If not set, the 'sql_select' is check to not be null.",
                        "type": "string",
                        "_annotation": false
                    }
                },
                "_annotation": "AbstractMachine",
                "required": [
                    "type"
                ]
            },
            "_annotation": "AbstractMachine"
        },
        "flupdo_resource": {
            "description": "Context property containing the Flupdo instance connected to database.",
            "type": "string",
            "default": "database",
            "_annotation": false
        },
        "auth_resource": {
            "description": "Context property containing the authenticator (IAuth)",
            "type": "string",
            "default": "auth",
            "_annotation": false
        },
        "sphinx_resource": {
            "description": "Context property containing the Flupdo resource connected to a Sphinx search engine.",
            "type": [
                "null",
                "string"
            ],
            "default": null,
            "_annotation": false
        },
        "table": {
            "description": "Name of the SQL table where state machines of this type are stored.",
            "type": "string",
            "_annotation": false
        },
        "table_alias": {
            "description": "",
            "type": [
                "null",
                "string"
            ],
            "default": null,
            "_annotation": false
        },
        "url": {
            "description": "Format string to generate machine URL",
            "type": [
                "string",
                "null"
            ],
            "_annotation": false
        },
        "parent_url": {
            "description": "Format string to generate URL of machine which is parent of this machine (for post-delete redirect)",
            "type": [
                "string",
                "null"
            ],
            "_annotation": false
        },
        "post_action_url": {
            "description": "Format string to generate URL where to redirect after action is invoked.",
            "type": [
                "string",
                "null"
            ],
            "_annotation": false
        }
    },
    "_annotation": false
}