local fileroot = ".\\modules\\EvoSwitcher\\EvoGoal"

local function make_key(ctx, filename)
    if ctx.home_team == 113 then
        GoalSong = "Team\\Marseille"
    elseif ctx.home_team == 109 then
        GoalSong = "Team\\Real Madrid"
    elseif ctx.home_team == 114 then
        GoalSong = "Team\\PSG"
    elseif ctx.home_team == 135 then
        GoalSong = "Team\\Spartak"
    elseif ctx.home_team == 172 then
        GoalSong = "Team\\Atletico"
    elseif ctx.home_team == 133 then
        GoalSong = "Team\\Olympiakos"
    elseif ctx.home_team == 130 then
        GoalSong = "Team\\Galatasaray"
    elseif ctx.home_team == 265 then
        GoalSong = "Team\\Seville"
    elseif ctx.home_team == 4146 then
        GoalSong = "Team\\Eibar"
    elseif ctx.home_team == 1232 then
        GoalSong = "Team\\Shakhtar"
    elseif ctx.home_team == 251 then
        GoalSong = "Team\\Utrecht"
    elseif ctx.home_team == 252 then
        GoalSong = "Team\\Vitesse"
    elseif ctx.home_team == 197 then
        GoalSong = "Team\\Fenerbahce"
    elseif ctx.home_team == 218 then
        GoalSong = "Team\\Rennes"
    elseif ctx.home_team == 242 then
        GoalSong = "Team\\Alkmaar"
    elseif ctx.home_team == 184 then
        GoalSong = "Team\\Schalke"
    elseif ctx.home_team == 191 then
        GoalSong = "Team\\Benfica"
    elseif ctx.home_team == 192 then
        GoalSong = "Team\\Porto"
    elseif ctx.home_team == 122 then
        GoalSong = "Team\\Lazio"
    elseif ctx.home_team == 124 then
        GoalSong = "Team\\Fiorentina"
    elseif ctx.home_team == 174 then
        GoalSong = "Team\\Anderlecht"
    elseif ctx.home_team == 120 then
        GoalSong = "Team\\Juventus"
    elseif ctx.home_team == 121 then
        GoalSong = "Team\\Milan"
    elseif ctx.home_team == 117 then
        GoalSong = "Team\\Rotterdam"
    elseif ctx.home_team == 118 then
        GoalSong = "Team\\PSV"
    elseif ctx.home_team == 119 then
        GoalSong = "Team\\Inter"
    elseif ctx.home_team == 1217 then
        GoalSong = "Team\\CSKA"
    elseif ctx.home_team == 1218 then
        GoalSong = "Team\\Zenit"
    elseif ctx.home_team == 1207 then
        GoalSong = "Team\\Kobenhavn"
    elseif ctx.home_team == 1212 then
        GoalSong = "Team\\PAOK"
    elseif ctx.home_team == 267 then
        GoalSong = "Team\\Villareal"
    elseif ctx.home_team == 273 then
        GoalSong = "Team\\Besiktas"
    else
        GoalSong = nil
    end
    if GoalSong ~= nil then
        return string.format("%s:%s", GoalSong, filename)
    end
end

local function get_filepath(ctx, filename, key)
    if key and GoalSong ~= nil then
        return string.format("%s\\%s\\%s", fileroot, GoalSong, filename)
    end
end

function make_log(ctx)
    if GoalSong ~= nil then
       logResult = GoalSong
       logResult = string.gsub(logResult, "Team\\", "")
       log("---- " .. logResult)
    end
end

local function init(ctx)
    if fileroot:sub(1,1)=='.' then
        fileroot = ctx.sider_dir .. fileroot
    end
    ctx.register("trophy_rewrite", make_log)
    ctx.register("livecpk_make_key", make_key)
    ctx.register("livecpk_get_filepath", get_filepath)
end

return { init = init }