local function exp(is_build, sysbuild, zephyr_base, zephyr_ws, board, runner)
    return {
        is_build = is_build,
        sysbuild = sysbuild,
        zephyr_base = zephyr_base,
        zephyr_ws = zephyr_ws,
        board = board,
        runner = runner,
    }
end

local zbs = 't/zephyrproject/zephyr'
local zws = 't/zephyrproject'
local b = 'test_board'
local r = 'test_runner'

local zconf = {
    path = 't/zephyrproject/app/zconf.lua',
    content = [[
    return {
        board = 'test_board',
        runner = 'test_runner'
    }
    ]],
}

local sb = {
    path = 't/zephyrproject/app/sysbuild.conf',
    content = ' ',
}

local conf = {
    [1] = {
        dirs = { 't', 't/t2', 't2/t3' },
        dst = 3,
        files = {},
        exp = exp(false, false, '', '', nil, nil),
    },

    [2] = {
        dirs = { 't', 't/zephyrproject', 't/zephyrproject/zephyr', 't/zephyrproject/app' },
        dst = 4,
        files = {},
        exp = exp(false, false, zbs, zws, nil, nil),
    },

    [3] = {
        dirs = { 't', 't/zephyrproject', 't/zephyrproject/zephyr', 't/zephyrproject/app' },
        dst = 4,
        files = { zconf },
        exp = exp(false, false, zbs, zws, b, r),
    },

    [4] = {
        dirs = { 't', 't/t2', 't/t2/build' },
        dst = 3,
        files = {},
        exp = exp(true, false, '', '', nil, nil),
    },

    [5] = {
        dirs = { 't', 't/zephyrproject', 't/zephyrproject/zephyr', 't/zephyrproject/app', 't/zephyrproject/app/build' },
        dst = 4,
        files = {},
        exp = exp(false, false, zbs, zws, nil, nil),
    },

    [6] = {
        dirs = { 't', 't/zephyrproject', 't/zephyrproject/zephyr', 't/zephyrproject/app', 't/zephyrproject/app/build' },
        dst = 5,
        files = {},
        exp = exp(true, false, zbs, zws, nil, nil),
    },

    [7] = {
        dirs = { 't', 't/zephyrproject', 't/zephyrproject/zephyr', 't/zephyrproject/app', 't/zephyrproject/app/build' },
        dst = 5,
        files = { zconf, sb },
        exp = exp(true, true, zbs, zws, b, r),
    },

    [8] = {
        dirs = { 't', 't/zephyrproject', 't/zephyrproject/zephyr', 't/zephyrproject/app', 't/zephyrproject/app/build' },
        dst = 4,
        files = { zconf, sb },
        exp = exp(false, true, zbs, zws, b, r),
    },
}

function conf.build_exp(tc, tmp)
    local vals = tc.exp
    local cwd = tmp .. '/' .. tc.dirs[tc.dst]
    local project_dir = cwd
    local start = cwd:match('^(.*)/build/[^/]+$')
    if start then
        project_dir = start
    else
        start = cwd:match('^(.*)/build$')
        if start then
            project_dir = start
        end
    end

    return {
        board = vals.board,
        cwd = cwd,
        is_build = vals.is_build,
        runner = vals.runner,
        sysbuild = vals.sysbuild,
        zephyr_base = vals.zephyr_ws ~= '' and tmp .. '/' .. vals.zephyr_base or '',
        zephyr_ws = vals.zephyr_ws ~= '' and tmp .. '/' .. vals.zephyr_ws or '',
        build_dir = 'build',
        project_dir = project_dir,
    }
end

return conf
