local c={}function c.switch(c,e,Q)if type(e)~="\116\097\098\108\101"then error("\076\065\046\085\116\105\108\105\116\121\046\115\119\105\116\099\104\058 \099\097\115\101\115 \109\117\115\116 \098\101 \097 \116\097\098\108\101")end local l=nil for Q in pairs(e)do if Q==c then l=e[Q]break end end local k=e.default if Q and not k then error("\076\065\046\085\116\105\108\105\116\121\046\115\119\105\116\099\104\058 \099\097\115\101 \091\'\100\101\102\097\117\108\116\'\093 \109\117\115\116 \098\101 \112\114\101\115\101\110\116 \119\104\101\110 \'\115\116\114\105\099\116\' \105\115 \116\114\117\101")end local d=l or k or function()return nil end if type(d)~="\102\117\110\099\116\105\111\110"then error("\076\065\046\085\116\105\108\105\116\121\046\115\119\105\116\099\104\058 \099\097\115\101\058"..(tostring(c).."\109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110"))end return d()or nil end function c.try(c)if type(c)~="\102\117\110\099\116\105\111\110"then error("\076\065\046\085\116\105\108\105\116\121\046\116\114\121\058 \102\117\110\099 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110")end local e={}local Q,l=pcall(c)function e.catch(e,c)if c~=nil and type(c)~="\102\117\110\099\116\105\111\110"then error("\076\065\046\085\116\105\108\105\116\121\046\116\114\121\046\099\097\116\099\104\058 \102\117\110\099\050 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110 \119\104\101\110 \115\112\101\099\105\102\105\101\100")end if Q then return l end return c and c(l)or nil end return e end function c.validate(c,e)if type(c)~="\116\097\098\108\101"then error("\076\065\046\085\116\105\108\105\116\121\046\118\097\108\105\100\097\116\101\058 \116\097\098\108\101 \109\117\115\116 \098\101 \097 \116\097\098\108\101")end local Q=true for c,Q in pairs(c)do if Q~=e then return false end end return true end return c
--------------------------------------------------------------------------------------------------------------------------------
--[[                                             Copyright (C) Inertia Lighting                                             ]]--
--------------------------------------------------------------------------------------------------------------------------------

local Utility = {}

--------------------------------------------------------------------------------------------------------------------------------

--- Basic switch statement for lua that supports having a return value
--- @param condition any the condition to look for within the cases table
--- @param cases table a table of cases to map conditions and cases to
--- @param strict boolean whether or not to throw an error if a default case was not found
--- @returns any the the value returned by the case that was executed
function Utility.switch(condition, cases, strict)
    if type(cases) ~= 'table' then
        error('LA.Utility.switch: cases must be a table')
    end

    local specifiedCase = nil
    for caseCondition in pairs(cases) do
        if caseCondition == condition then
            specifiedCase = cases[caseCondition]
            break
        end
    end

    local defaultCase = cases['default']

    if strict and not defaultCase then
        error('LA.Utility.switch: case [\'default\'] must be present when \'strict\' is true')
    end

    local case = specifiedCase or defaultCase or (function() return nil end)

    if type(case) ~= 'function' then
        error('LA.Utility.switch: case:' .. tostring(condition) .. 'must be a function')
    end

    return case() or nil
end

--- Implements a basic try-catch block for lua
--- @param func function the function to try via pcall
--- @returns t table a table containing a chain-able ':catch(cb?)' callback
function Utility.try(func)
    if type(func) ~= 'function' then
        error('LA.Utility.try: func must be a function')
    end

    local t = {}

    local success, result = pcall(func)

    function t:catch(func2)
        if func2 ~= nil and type(func2) ~= 'function' then
            error('LA.Utility.try.catch: func2 must be a function when specified')
        end

        if success then return result end

        return func2 and func2(result) or nil
    end

    return t
end

--- Implements a batched validation function for checking conditions
--- @param table table of items that you want to check
--- @param expected the expected value of all the ietms in the table
--- @returns Boolean The result of if all the items in the table are equal to the expected result
function Utility.validate(table, expected)
    if type(table) ~= 'table' then
        error('LA.Utility.validate: table must be a table')
    end
    
    local result = true

    for _,item in pairs(table) do
        if item ~= expected then
            return false
        end
    end
    
    return true
end

--------------------------------------------------------------------------------------------------------------------------------

return Utility