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

local tid

function make_key(ctx, filename)
    tid = ctx.tournament_id
    home = ctx.home_team
    away = ctx.away_team
    -- Competition
    if tid == 2 or tid == 3 or tid == 4 or tid == 400 or tid == 401 or tid == 402 or tid == 403 or tid == 404 or tid == 405 or tid == 406 or tid == 600  or tid == 601 or tid == 602 or tid == 603 or tid == 604 or tid == 605 or tid == 606 or tid == 607 then
        if (home == 101 or home == 4071 or home == 377 or home == 378 or home == 379 or home == 102 or home == 382 or home == 177 or home == 178 or home == 2610 or home == 204 or home == 103 or home == 173 or home == 100 or home == 106 or home == 207 or home == 179 or home == 398 or home == 105 or home == 208) and (away == 101 or away == 4071 or away == 377 or away == 378 or away == 379 or away == 102 or away == 382 or away == 177 or away == 178 or away == 2610 or away == 204 or away == 103 or away == 173 or away == 100 or away == 106 or away == 207 or away == 179 or away == 398 or away == 105 or away == 208) then
	        EvoPressRoom = "Competition\\UEFA Champions League\\England"
	    elseif (home == 199 or home == 2293 or home == 2297 or home == 2298 or home == 2300 or home == 2301 or home == 2344 or home == 2345 or home == 2346 or home == 2347 or home == 2348 or home == 2349 or home == 2350 or home == 2351 or home == 2352 or home == 2353 or home == 2354 or home == 2355 or home == 2356 or home == 2357) and (away == 199 or away == 2293 or away == 2297 or away == 2298 or away == 2300 or away == 2301 or away == 2344 or away == 2345 or away == 2346 or away == 2347 or away == 2348 or away == 2349 or away == 2350 or away == 2351 or away == 2352 or away == 2353 or away == 2354 or away == 2355 or away == 2356 or away == 2357) then
	        EvoPressRoom = "Competition\\UEFA Champions League\\Germany"
		elseif (home == 234 or home == 186 or home == 320 or home == 188 or home == 235 or home == 124 or home == 323 or home == 119 or home == 120 or home == 122 or home == 121 or home == 327 or home == 123 or home == 125 or home == 240 or home == 1919 or home == 4923 or home == 4234 or home == 333 or home == 190) and (away == 234 or away == 186 or away == 320 or away == 188 or away == 235 or away == 124 or away == 323 or away == 119 or away == 120 or away == 122 or away == 121 or away == 327 or away == 123 or away == 125 or away == 240 or away == 1919 or away == 4923 or away == 4234 or away == 333 or away == 190) then
	        EvoPressRoom = "Competition\\UEFA Champions League\\Italy"
		elseif (home == 258 or home == 172 or home == 108 or home == 195 or home == 4145 or home == 4146 or home == 259 or home == 362 or home == 2187 or home == 2188 or home == 4272 or home == 366 or home == 370 or home == 194 or home == 109 or home == 196 or home == 266 or home == 265 or home == 110 or home == 267) and (away == 258 or away == 172 or away == 108 or away == 195 or away == 4145 or away == 4146 or away == 259 or away == 362 or away == 2187 or away == 2188 or away == 4272 or away == 366 or away == 370 or away == 194 or away == 109 or away == 196 or away == 266 or away == 265 or away == 110 or away == 267) then
	        EvoPressRoom = "Competition\\UEFA Champions League\\Spain"
		elseif (home == 4200 or home == 403 or home == 115 or home == 405 or home == 1328 or home == 211 or home == 213 or home == 112 or home == 215 or home == 216 or home == 217 or home == 1910 or home == 181 or home == 113 or home == 114 or home == 218 or home == 418 or home == 1330 or home == 4213 or home == 221) and (away == 4200 or away == 403 or away == 115 or away == 405 or away == 1328 or away == 211 or away == 213 or away == 112 or away == 215 or away == 216 or away == 217 or away == 1910 or away == 181 or away == 113 or away == 114 or away == 218 or away == 418 or away == 1330 or away == 4213 or away == 221) then
	        EvoPressRoom = "Competition\\UEFA Champions League\\France"
	    elseif (home == 243 or home == 116 or home == 242 or home == 339 or home == 342 or home == 344 or home == 117 or home == 345 or home == 244 or home == 245 or home == 349 or home == 246 or home == 256 or home == 118 or home == 251 or home == 252 or home == 355 or home == 255) and (away == 243 or away == 116 or away == 242 or away == 339 or away == 342 or away == 344 or away == 117 or away == 345 or away == 244 or away == 245 or away == 349 or away == 246 or away == 256 or away == 118 or away == 251 or away == 252 or away == 355 or away == 255) then
	        EvoPressRoom = "Competition\\UEFA Champions League\\Netherlands"
	    elseif (home == 174 or home == 5191 or home == 2009 or home == 269 or home == 1195 or home == 1196 or home == 5190 or home == 2013 or home == 5192 or home == 1199 or home == 5193 or home == 5194 or home == 2010 or home == 1197 or home == 5195 or home == 2019) and (away == 174 or away == 5191 or away == 2009 or away == 269 or away == 1195 or away == 1196 or away == 5190 or away == 2013 or away == 5192 or away == 1199 or away == 5193 or away == 5194 or away == 2010 or away == 1197 or away == 5195 or away == 2019) then
	        EvoPressRoom = "Competition\\UEFA Champions League\\Belgium"
		else
			EvoPressRoom = "Competition\\UEFA Champions League\\Default"
		end
    elseif tid == 5 or tid == 1000 or tid == 1001 or tid == 1002 or tid == 1003 or tid == 1004 or tid == 1005 or tid == 1006 or tid == 1007 or tid == 1008 or tid == 1009  or tid == 1010 or tid == 1011 or tid == 6 then
          EvoPressRoom = "Competition\\UEFA Europa League"
    else
         -- Club
         if home == 116 or away == 116 then
            EvoPressRoom = "Club\\AFC Ajax"
         elseif home == 172 or away == 172 then
            EvoPressRoom = "Club\\Atletico de Madrid"
         --elseif home == xxx or away == xxx then
            --EvoPressRoom = "Club\\Bayern Munchen"
         elseif home == 139 or away == 139 then
            EvoPressRoom = "Club\\Boca Juniors"
         --elseif home == xxx or away == xxx then
            --EvoPressRoom = "Club\\Borussia Dortmund"
         --elseif home == xxx or away == xxx then
            --EvoPressRoom = "Club\\Guadalajara"
         elseif home == 120 or away == 120 then
            EvoPressRoom = "Club\\Juventus"
         elseif home == 100 or away == 100 then
            EvoPressRoom = "Club\\Manchester United"
         elseif home == 389 or away == 389 then
            EvoPressRoom = "Club\\Nottingham Forest"
         elseif home == 114 or away == 114 then
            EvoPressRoom = "Club\\PSG"
         elseif home == 370 or away == 370 then
            EvoPressRoom = "Club\\Rayo Vallecano"  
         elseif home == 194 or away == 194 then
            EvoPressRoom = "Club\\Real Betis"  
         elseif home == 109 or away == 109 then
            EvoPressRoom = "Club\\Real Madrid"  
         elseif home == 2216 or away == 2216 then
            EvoPressRoom = "Club\\Sporting Cristal"  
         elseif home == 179 or away == 179 then
            EvoPressRoom = "Club\\Tottenham Hotspur"  
         elseif home == 193 or away == 193 then
			EvoPressRoom = "Club\\Sporting Lisboa"
	     elseif home == 113 or away == 113 then
			EvoPressRoom = "Club\\OM"
		 elseif home == 395 or away == 395 then
			EvoPressRoom = "Club\\Stoke City"	
 
         -- National
         elseif home == 14 or away == 14 then
            EvoPressRoom = "National\\Germany"
         elseif home == 7 or away == 7 then
            EvoPressRoom = "National\\Spain"
         else
            EvoPressRoom = "Default"
         end
    end

    if tid then
       return string.format("%s:%s", EvoPressRoom, filename)
    end
end

local function get_filepath(ctx, filename, key)
    if key then
        return string.format("%s\\%s\\%s", fileroot, EvoPressRoom, filename)
    end
end

local function trophy_rewrite(ctx, tournament_id)
       EvoPressRoom = string.gsub(EvoPressRoom, "Competition\\", "")
       EvoPressRoom = string.gsub(EvoPressRoom, "National\\", "")
       EvoPressRoom = string.gsub(EvoPressRoom, "Club\\", "")
       EvoPressRoom = string.gsub(EvoPressRoom, "\\", " ")
       log("--- " .. EvoPressRoom)
end

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

return { init = init }