-- local bindModule = require(script.Parent.Parent.bind)
-- type EachTests = bindModule.EachTests

type EachTests = any
local interpolationModule = require(script.Parent.interpolation)
type Headings = interpolationModule.Headings
type Template = interpolationModule.Template
type Templates = interpolationModule.Templates
local interpolateVariables = require(script.Parent.interpolation).interpolateVariables

local function default(title: string, headings: Headings, row: Global_Row): EachTests
	local table_ = convertRowToTable(row, headings)
	local templates = convertTableToTemplates(table_, headings)
	return Array.map(templates, function(template, index)
		return {
			arguments = { Object.assign({}, template) },
			-- ROBLOX FIXME Luau: analyze should know this is Template because of the Array.map() generic's callbackFn
			title = interpolateVariables(title, template :: Template, index),
		}
	end)
end

exports.default = default

function convertRowToTable(row: Global_Row, _headings: Headings): Global_Table
	-- ROBLOX deviation: rows are already formatted as arrays (because there are no tagged templates)
	return row
end

function convertTableToTemplates(table_: Global_Table, headings: Headings): Templates
	return Array.map(table_, function(row)
		return Array.reduce(row, function(acc, value, index)
			return Object.assign(acc, { [headings[index]] = value })
		end, {})
	end)
end

return exports
