local _AddonName, _EchoRaidTools = ...;


local module = _EchoRaidTools:GetModule("todo-list")


---comment
---@param t table
---@return table
function module:DeepCopy(t)
    if type(t) ~= "table" then return t end
    local ret = {}
    for key, value in pairs(t) do
        ret[key] = module:DeepCopy(value)
    end
    return ret
end

---true if they match
---@param t table
---@param tcompare table
---@return boolean
function module:DeepCompare(t, tcompare)
    local tType = type(t)
    local tCompareType = type(tcompare)

    if tType ~= tCompareType then return false end

    if tType == "table" then
        for key, value in pairs(t) do
            if not module:DeepCompare(value, tcompare[key]) then
                return false
            end
        end
    elseif t ~= tcompare then
        return false
    end
    return true
end

function module:SetField(t, fieldTable, value)
    local current = t
    for i, key in ipairs(fieldTable) do
        if i == #fieldTable then
            local changed = current[key] ~= value
            current[key] = value
            return changed
        else
            current[key] = current[key] or {}
            current = current[key]
        end
    end
end

function module:GetField(t, fieldTable)
    local current = t
    for i, key in ipairs(fieldTable) do
        current = current[key]
        if not current then
            break
        end
    end
    return current
end
