-- Autogenerated with DRAKON Editor 1.32
local table = table
local string = string
local pairs = pairs
local ipairs = ipairs
local type = type
local print = print
local os = os
local tostring = tostring

local global_cfg = global_cfg

local clock = require("clock")
local log = require("log")
local digest = require("digest")
local fiber = require("fiber")

local utf8 = require("lua-utf8")

local utils = require("utils")
local space = require("space")
local db = require(global_cfg.db)

setfenv(1, {}) 

local module = {}

function ac(items, id, one)
    -- item 81
    id = tostring(id)
    one = tostring(one)
    -- item 65
    add_item(
        items,
        id,
        {type="action", text=id, one=one}
    )
end

function add_branch0(items, one)
    local item
    -- item 47
    item = {
        branchId = 0,
        type = "branch",
        one = one
    }
    -- item 46
    add_item(
        items,
        "2",
        item
    )
end

function add_item(items, id, fields)
    -- item 14
    fields.id = id
    -- item 13
    table.insert(
        items,
        fields
    )
end

function add_items(space_id, folder_id, items)
    for _, item in ipairs(items) do
        -- item 22
        db.item_insert(
            space_id,
            folder_id,
            item.id,
            item
        )
    end
end

function al(items, id, one)
    -- item 284
    id = tostring(id)
    one = tostring(one)
    -- item 283
    add_item(
        items,
        id,
        {type="arrow-loop", one=one}
    )
end

function ar01()
    local items
    -- item 275
    items = {}
    -- item 276
    add_branch0(
        items,
        "20"
    )
    -- item 285
    al(items, 20, 3)
    -- item 277
    qu(items, 3, 1, 20)
    -- item 274
    make_folder(
        "ar01",
        items
    )
end

function ar02()
    local items
    -- item 290
    items = {}
    -- item 291
    add_branch0(
        items,
        "20"
    )
    -- item 293
    al(items, 20, 3)
    -- item 292
    qu(items, 3, 1, 4)
    -- item 294
    ac(items, 4, 20)
    -- item 289
    make_folder(
        "ar02",
        items
    )
end

function ar03()
    local items
    -- item 299
    items = {}
    -- item 300
    add_branch0(
        items,
        "20"
    )
    -- item 302
    al(items, 20, 3)
    -- item 301
    qu(items, 3, 5, 20)
    -- item 303
    qu(items, 5, 1, 20)
    -- item 298
    make_folder(
        "ar03",
        items
    )
end

function ar04()
    local items
    -- item 308
    items = {}
    -- item 309
    add_branch0(
        items,
        "20"
    )
    -- item 311
    al(items, 20, 3)
    -- item 310
    qu(items, 3, 5, 4)
    -- item 312
    qu(items, 5, 1, 4)
    -- item 313
    ac(items, 4, 20)
    -- item 307
    make_folder(
        "ar04",
        items
    )
end

function ar05()
    local items
    -- item 318
    items = {}
    -- item 319
    add_branch0(
        items,
        "20"
    )
    -- item 321
    al(items, 20, 3)
    -- item 320
    qu(items, 3, 5, 4)
    -- item 322
    qu(items, 5, 1, 20)
    -- item 323
    ac(items, 4, 20)
    -- item 317
    make_folder(
        "ar05",
        items
    )
end

function ar06()
    local items
    -- item 328
    items = {}
    -- item 329
    add_branch0(
        items,
        "20"
    )
    -- item 331
    al(items, 20, 3)
    -- item 348
    se(items, 3, 4)
    -- item 330
    ca(items, 4, 1, 5)
    -- item 349
    ca(items, 5, 1, 6)
    -- item 350
    ca(items, 6, 20, "")
    -- item 327
    make_folder(
        "ar06",
        items
    )
end

function ar07()
    local items
    -- item 355
    items = {}
    -- item 356
    add_branch0(
        items,
        "20"
    )
    -- item 358
    al(items, 20, 3)
    -- item 359
    se(items, 3, 4)
    -- item 357
    ca(items, 4, 1, 5)
    -- item 360
    ca(items, 5, 20, 6)
    -- item 361
    ca(items, 6, 20, "")
    -- item 354
    make_folder(
        "ar07",
        items
    )
end

function ar08()
    local items
    -- item 366
    items = {}
    -- item 367
    add_branch0(
        items,
        "20"
    )
    -- item 369
    al(items, 20, 3)
    -- item 370
    se(items, 3, 4)
    -- item 368
    ca(items, 4, 1, 5)
    -- item 371
    ca(items, 5, 20, 6)
    -- item 372
    ca(items, 6, 7, "")
    -- item 373
    qu(items, 7, 20, 20)
    -- item 365
    make_folder(
        "ar08",
        items
    )
end

function ar09()
    local items
    -- item 378
    items = {}
    -- item 379
    add_branch0(
        items,
        "20"
    )
    -- item 381
    al(items, 20, 3)
    -- item 382
    se(items, 3, 4)
    -- item 380
    ca(items, 4, 1, 5)
    -- item 383
    ca(items, 5, 20, 6)
    -- item 384
    ca(items, 6, 7, "")
    -- item 385
    qu(items, 7, 20, 8)
    -- item 386
    ac(items, 8, 20)
    -- item 377
    make_folder(
        "ar09",
        items
    )
end

function ar10()
    local items
    -- item 392
    items = {}
    -- item 393
    add_branch0(
        items,
        "20"
    )
    -- item 395
    al(items, 20, 3)
    -- item 396
    se(items, 3, 4)
    -- item 394
    ca(items, 4, 1, 5)
    -- item 397
    ca(items, 5, 7, 6)
    -- item 398
    ca(items, 6, 20, "")
    -- item 399
    qu(items, 7, 20, 8)
    -- item 400
    ac(items, 8, 20)
    -- item 391
    make_folder(
        "ar10",
        items
    )
end

function ar11()
    local items
    -- item 405
    items = {}
    -- item 406
    add_branch0(
        items,
        "20"
    )
    -- item 408
    al(items, 20, 3)
    -- item 409
    se(items, 3, 4)
    -- item 407
    ca(items, 4, 1, 5)
    -- item 410
    ca(items, 5, 7, 6)
    -- item 411
    ca(items, 6, 20, "")
    -- item 412
    qu(items, 7, 20, 20)
    -- item 404
    make_folder(
        "ar11",
        items
    )
end

function ar12()
    local items
    -- item 417
    items = {}
    -- item 418
    add_branch0(
        items,
        "20"
    )
    -- item 420
    al(items, 20, 3)
    -- item 419
    qu(items, 3, 1, 5)
    -- item 421
    qu(items, 5, 1, 4)
    -- item 422
    ac(items, 4, 20)
    -- item 416
    make_folder(
        "ar12",
        items
    )
end

function ca(items, id, one, two)
    -- item 340
    id = tostring(id)
    one = tostring(one)
    two = tostring(two)
    -- item 339
    add_item(
        items,
        id,
        {type="case", text=id, one=one, two=two}
    )
end

function d01()
    local items
    -- item 29
    items = {}
    -- item 70
    add_branch0(
        items,
        "1"
    )
    -- item 28
    make_folder(
        "d01",
        items
    )
end

function d02()
    local items
    -- item 78
    items = {}
    -- item 79
    add_branch0(
        items,
        "3"
    )
    -- item 80
    ac(items, 3, 4)
    -- item 83
    ac(items, 4, 5)
    -- item 84
    ac(items, 5, 1)
    -- item 77
    make_folder(
        "d02",
        items
    )
end

function d03()
    local items
    -- item 91
    items = {}
    -- item 92
    add_branch0(
        items,
        "3"
    )
    -- item 93
    qu(items, 3, 1, 1)
    -- item 90
    make_folder(
        "d03",
        items
    )
end

function d04()
    local items
    -- item 98
    items = {}
    -- item 99
    add_branch0(
        items,
        "3"
    )
    -- item 100
    qu(items, 3, 4, 1)
    -- item 101
    ac(items, 4, 1)
    -- item 97
    make_folder(
        "d04",
        items
    )
end

function d05()
    local items
    -- item 106
    items = {}
    -- item 107
    add_branch0(
        items,
        "3"
    )
    -- item 108
    qu(items, 3, 1, 4)
    -- item 109
    ac(items, 4, 1)
    -- item 105
    make_folder(
        "d05",
        items
    )
end

function d06()
    local items
    -- item 114
    items = {}
    -- item 115
    add_branch0(
        items,
        "3"
    )
    -- item 116
    qu(items, 3, 4, 5)
    -- item 117
    ac(items, 4, 1)
    -- item 118
    ac(items, 5, 1)
    -- item 113
    make_folder(
        "d06",
        items
    )
end

function d07()
    local items
    -- item 123
    items = {}
    -- item 124
    add_branch0(
        items,
        "3"
    )
    -- item 125
    qu(items, 3, 5, 4)
    -- item 127
    ac(items, 5, 1)
    -- item 128
    qu(items, 4, 6, 7)
    -- item 129
    ac(items, 6, 1)
    -- item 130
    ac(items, 7, 1)
    -- item 122
    make_folder(
        "d07",
        items
    )
end

function d08()
    local items
    -- item 135
    items = {}
    -- item 136
    add_branch0(
        items,
        "3"
    )
    -- item 137
    qu(items, 3, 4, 1)
    -- item 142
    qu(items, 4, 1, 1)
    -- item 134
    make_folder(
        "d08",
        items
    )
end

function d09()
    local items
    -- item 147
    items = {}
    -- item 148
    add_branch0(
        items,
        "3"
    )
    -- item 149
    qu(items, 3, 4, 5)
    -- item 150
    qu(items, 4, 6, 5)
    -- item 151
    ac(items, 6, 1)
    -- item 152
    ac(items, 5, 1)
    -- item 146
    make_folder(
        "d09",
        items
    )
end

function d10()
    local items
    -- item 157
    items = {}
    -- item 158
    add_branch0(
        items,
        "3"
    )
    -- item 159
    qu(items, 3, 4, 5)
    -- item 160
    qu(items, 4, 6, 7)
    -- item 161
    ac(items, 6, 1)
    -- item 162
    ac(items, 5, 7)
    -- item 163
    ac(items, 7, 1)
    -- item 156
    make_folder(
        "d10",
        items
    )
end

function d11()
    local items
    -- item 168
    items = {}
    -- item 169
    add_branch0(
        items,
        "3"
    )
    -- item 170
    qu(items, 3, 5, 4)
    -- item 171
    qu(items, 4, 5, 6)
    -- item 172
    ac(items, 6, 1)
    -- item 173
    ac(items, 5, 1)
    -- item 167
    make_folder(
        "d11",
        items
    )
end

function d12()
    local items
    -- item 178
    items = {}
    -- item 179
    add_branch0(
        items,
        "3"
    )
    -- item 180
    qu(items, 3, 5, 4)
    -- item 181
    qu(items, 4, 5, 7)
    -- item 184
    qu(items, 7, 5, 6)
    -- item 182
    ac(items, 6, 1)
    -- item 183
    ac(items, 5, 1)
    -- item 177
    make_folder(
        "d12",
        items
    )
end

function d13()
    local items
    -- item 189
    items = {}
    -- item 190
    add_branch0(
        items,
        "3"
    )
    -- item 191
    qu(items, 3, 8, 4)
    -- item 192
    qu(items, 8, 5, 9)
    -- item 195
    qu(items, 4, 6, 7)
    -- item 193
    ac(items, 6, 1)
    -- item 194
    ac(items, 5, 1)
    -- item 196
    ac(items, 9, 1)
    -- item 197
    ac(items, 7, 1)
    -- item 188
    make_folder(
        "d13",
        items
    )
end

function d14()
    local items
    -- item 202
    items = {}
    -- item 203
    add_branch0(
        items,
        "3"
    )
    -- item 204
    qu(items, 3, 8, 4)
    -- item 205
    qu(items, 8, 5, 9)
    -- item 208
    qu(items, 4, 6, 7)
    -- item 206
    ac(items, 6, 11)
    -- item 207
    ac(items, 5, 10)
    -- item 209
    ac(items, 9, 10)
    -- item 210
    ac(items, 7, 11)
    -- item 211
    ac(items, 10, 1)
    -- item 212
    ac(items, 11, 1)
    -- item 201
    make_folder(
        "d14",
        items
    )
end

function d15()
    local items
    -- item 217
    items = {}
    -- item 218
    add_branch0(
        items,
        "3"
    )
    -- item 219
    qu(items, 3, 5, 4)
    -- item 220
    qu(items, 4, 6, 9)
    -- item 221
    ac(items, 6, 7)
    -- item 222
    ac(items, 5, 7)
    -- item 223
    qu(items, 7, 8, 9)
    -- item 224
    ac(items, 9, 1)
    -- item 225
    ac(items, 8, 1)
    -- item 216
    make_folder(
        "d15",
        items
    )
end

function d16()
    local items
    -- item 230
    items = {}
    -- item 231
    add_branch0(
        items,
        "3"
    )
    -- item 232
    qu(items, 3, 4, 6)
    -- item 233
    qu(items, 4, 1, 5)
    -- item 234
    ac(items, 6, 1)
    -- item 235
    ac(items, 5, 6)
    -- item 229
    make_folder(
        "d16",
        items
    )
end

function d17()
    local items
    -- item 241
    items = {}
    -- item 242
    add_branch0(
        items,
        "3"
    )
    -- item 243
    qu(items, 3, 4, 6)
    -- item 244
    qu(items, 4, 5, 1)
    -- item 247
    qu(items, 5, 1, 1)
    -- item 245
    ac(items, 6, 1)
    -- item 240
    make_folder(
        "d17",
        items
    )
end

function d18()
    local items
    -- item 252
    items = {}
    -- item 253
    add_branch0(
        items,
        "3"
    )
    -- item 254
    qu(items, 3, 4, 6)
    -- item 255
    qu(items, 4, 5, 7)
    -- item 257
    qu(items, 5, 1, 8)
    -- item 256
    ac(items, 6, 8)
    -- item 258
    ac(items, 7, 8)
    -- item 270
    ac(items, 8, 1)
    -- item 251
    make_folder(
        "d18",
        items
    )
end

function d19()
    local items
    -- item 263
    items = {}
    -- item 264
    add_branch0(
        items,
        "3"
    )
    -- item 265
    qu(items, 3, 4, 1)
    -- item 266
    qu(items, 4, 5, 6)
    -- item 267
    ac(items, 6, 1)
    -- item 269
    qu(items, 5, 1, 1)
    -- item 262
    make_folder(
        "d19",
        items
    )
end

function make_folder(name, items)
    local folder_empty, folder_id, item, ok, parent_id, space_id
    -- item 85
    space_id = module.space_id
    parent_id = module.parent_id
    -- item 39
    folder_empty = {
        name = name,
        type = "drakon",
        parent = parent_id
    }
    -- item 38
    ok, folder_id = space.create_folder(
        space_id,
        folder_empty,
        "admin",
        true
    )
    -- item 69
    item = {
        id = "1",
        type = "end"
    }
    -- item 68
    db.item_insert(
        space_id,
        folder_id,
        item.id,
        item
    )
    -- item 71
    add_items(
        space_id,
        folder_id,
        items
    )
    -- item 40
    return folder_id
end

function make_test_data(space_id, parent_id)
    -- item 86
    module.space_id = space_id
    module.parent_id = parent_id
    -- item 63
    d01()
    -- item 64
    d02()
    -- item 236
    d03()
    d04()
    d05()
    d06()
    d07()
    d08()
    d09()
    d10()
    d11()
    d12()
    d13()
    d14()
    d15()
    d16()
    d17()
    d18()
    d19()
    -- item 387
    ar01()
    ar02()
    ar03()
    ar04()
    ar05()
    ar06()
    ar07()
    ar08()
    ar09()
    ar10()
    ar11()
    ar12()
end

function qu(items, id, one, two)
    -- item 82
    id = tostring(id)
    one = tostring(one)
    two = tostring(two)
    -- item 66
    add_item(
        items,
        id,
        {type="question", text=id, one=one, two=two}
    )
end

function se(items, id, one)
    -- item 347
    id = tostring(id)
    one = tostring(one)
    -- item 346
    add_item(
        items,
        id,
        {type="select", text=id, one=one}
    )
end


return {
	make_test_data = make_test_data
}
