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

local tid

local function set_random(ctx)
	tid = ctx.tournament_id
	home = ctx.home_team
	away = ctx.away_team
end

function make_key(ctx, filename)
	-- Master League/BAL/League/Cup
    if tid == 17 then
		 EvoBoard = "Premier League"
	elseif tid == 79 or tid == 83 then
		 EvoBoard = "EFL"
	--elseif tid == 86 then
		 --EvoBoard = "Community Shield"
	--elseif tid == 19 then
		   --EvoBoard = "LaLiga"
	--elseif tid == 23 then
	     --EvoBoard = "FA Cup"
	--elseif tid == 18 then
	     --EvoBoard = "Serie A"
	--elseif tid == 20 then
		 --EvoBoard = "Ligue 1"
	--elseif tid == 26 then
		 --EvoBoard = "Coupe de France"
	--elseif tid == 21 then
		 --EvoBoard = "Eredivisie"
	--elseif tid == 118 then
		 --EvoBoard = "Super Lig"
	--elseif tid == 115 or tid == 155 or tid == 156 or tid == 157 or tid == 158 or tid == 159 then
		 --EvoBoard = "Jupiler Pro League"
	--elseif tid == 133 or tid == 134 or tid == 135 or tid == 136 or tid == 137 then
		 --EvoBoard = "SPFL"
	--elseif tid == 50 then
	     --EvoBoard = "Bundesliga"
	--elseif tid == 30 then
		 --EvoBoard = "Superliga Argentina"
	--elseif tid == 81 then
		 --EvoBoard = "Ligue 2"
	--elseif tid == 53 then
	     --EvoBoard = "DFB Pokal"
	--elseif tid == 95 then
	     --EvoBoard = "DFL Supercup"
	--elseif tid == 59 then
		 --EvoBoard = "Copa Argentina"	 
	--elseif tid == 8 or tid == 9 or tid == 10 or tid == 1600 or tid == 1601 or tid == 1602 or tid == 1603 or tid == 1604 or tid == 1605 or tid == 1800 or tid == 1801 or tid == 1802 or tid == 1803 or tid == 1804 or tid == 1805 or tid == 1806 or tid == 1807 then
		 --EvoBoard = "Copa Libertadores"
	--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
	     --EvoBoard = "UEFA Europa League"
	--elseif tid == 7 then
		 --EvoBoard = "UEFA Super Cup"
    --elseif 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
	      --EvoBoard = "UEFA Champions League"
	--elseif tid == 34 or tid == 35 or tid == 36 or tid == 37 or tid == 38 or tid == 39 or tid == 40 or tid == 6800 or tid == 6801 or tid == 6802 or tid == 6803 or tid == 6804 or tid == 6805 or tid == 6806 or tid == 6807 or tid == 7200 or tid == 7201 or tid == 7202 or tid == 7203 or tid == 7204 or tid == 7205 or tid == 7206 or tid == 7207 or tid == 7400 or tid == 7600 or tid == 7800 or tid == 7801 or tid == 8000 or tid == 8001 then
	     --EvoBoard = "FIFA World Cup"
	--elseif tid == 41 or tid == 42 or tid == 8200 or tid == 8201 or tid == 8202 or tid == 8203 or tid == 8204 or tid == 8205 then
	     --EvoBoard = "UEFA Euro"
	--elseif tid == 43 or tid == 45 or tid == 104 or tid == 8800 or tid == 8801 or tid == 8802 or tid == 8803 or tid == 20800 or tid == 20801 or tid == 20802 then
		 --EvoBoard = "Copa America"
	--elseif tid == 44 then
		 --EvoBoard = "AFC Asian Cup"
	--elseif tid == 46 then
		 --EvoBoard = "Africa Cup of Nations"
	--elseif tid == 1 then
		 --EvoBoard = "FIFA Club World Cup"
	--elseif tid == 105 or tid == 106 or tid == 107 then
		 --EvoBoard = "International Champions Cup"
	--elseif tid == 25 then
		 --EvoBoard = "Copa del Rey"
	--elseif tid == 87 then
		 --EvoBoard = "Supercopa de Espana"
	--elseif tid == 88 then
		 --EvoBoard = "Trophee des Champions"
	--elseif tid == 22 then
		 --EvoBoard = "Liga NOS"
	--elseif tid == 24 then
		 --EvoBoard = "Coppa Italia"
	--elseif tid == 89 then
		 --EvoBoard = "Supercoppa Italiana"
	--elseif tid == 27 then
		 --EvoBoard = "KNVB Beker"
	--elseif tid == 90 then
		 --EvoBoard = "Johan Cruyff Shield"
	--elseif tid == 28 then
		 --EvoBoard = "Taca de Portugal"
	--elseif tid == 91 then
		 --EvoBoard = "Supertaca Cândido de Oliveira"
	--elseif tid == 116 then
		 --EvoBoard = "Russian Premier League"
	--elseif tid == 123 then
		 --EvoBoard = "Russian Cup"
	--elseif tid == 123 then
		 --EvoBoard = "Russian Super Cup"
	--elseif tid == 117 then
		 --EvoBoard = "Raiffeisen Super League"
	--elseif tid == 124 then
		 --EvoBoard = "Swiss Cup"
	--elseif tid == 112 then
		 --EvoBoard = "Cofidis Cup"
	--elseif tid == 128 then
		 --EvoBoard = "Belgian Super Cup"
	--elseif tid == 125 then
		 --EvoBoard = "Turkish Cup"
	--elseif tid == 130 then
		 --EvoBoard = "Turkish Super Cup"
	--elseif tid == 141 or tid == 142 or tid == 147 or tid == 148 or tid == 149 or tid == 150 or tid == 151 then
		 --EvoBoard = "Danish Superliga"
	--elseif tid == 119 or tid == 23800 or tid == 23801 or tid == 160 or tid == 161 then
		 --EvoBoard = "Liga Aguila"
	--elseif tid == 126 then
		 --EvoBoard = "Copa Colombia"
	--elseif tid == 131 then
		 --EvoBoard = "Superliga Colombiana"
	--elseif tid == 67 or tid == 13400 or tid == 13401 then
		 --EvoBoard = "Chilean Primera Division"
	--elseif tid == 68 then
		 --EvoBoard = "Copa Chile"
	--elseif tid == 92 then
		 --EvoBoard = "Supercopa Argentina"
	--elseif tid == 29 then
		 --EvoBoard = "Brasileiro Serie A"
	--elseif tid == 31 then
		 --EvoBoard = "Copa do Brasil"
    elseif tid == 65535 or tid == 47 or tid == 99 or tid == 9400 or tid == 9401 or tid == 9402 or tid == 9403 or tid == 9404 or tid == 9405 or tid == 9406 or tid == 9407 or tid == 48 then
	    --Exhibition
	    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
	        EvoBoard = "Premier League"
		elseif (home == 107 or home == 201 or home == 176 or home == 202 or home == 4180 or home == 1760 or home == 383 or home == 1589 or home == 386 or home == 104 or home == 205 or home == 387 or home == 388 or home == 389 or home == 4192 or home == 1327 or home == 391 or home == 4193 or home == 4194 or home == 394 or home == 395 or home == 1909 or home == 399 or home == 400) and (away == 107 or away == 201 or away == 176 or away == 202 or away == 4180 or away == 1760 or away == 383 or away == 1589 or away == 386 or away == 104 or away == 205 or away == 387 or away == 388 or away == 389 or away == 4192 or away == 1327 or away == 391 or away == 4193 or away == 4194 or away == 394 or away == 395 or away == 1909 or away == 399 or away == 400) then
	        EvoBoard = "EFL"
	    --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
	        --EvoBoard = "Bundesliga"
		--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
	        --EvoBoard = "Serie A"
		--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
		    --EvoBoard = "LaLiga"
		--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
	        --EvoBoard = "Ligue 1"
	    --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
	        --EvoBoard = "Eredivisie"
	    --elseif (home == 2623 or home == 5202 or home == 5360 or home == 1989 or home == 5353 or home == 273 or home == 1991 or home == 197 or home == 130 or home == 5203 or home == 1995 or home == 2625 or home == 1996 or home == 5204 or home == 5354 or home == 1809 or home == 1945 or home == 5206) and (away == 2623 or away == 5202 or away == 5360 or away == 1989 or away == 5353 or away == 273 or away == 1991 or away == 197 or away == 130 or away == 5203 or away == 1995 or away == 2625 or away == 1996 or away == 5204 or away == 5354 or away == 1809 or away == 1945 or away == 5206) then
	        --EvoBoard = "Super Lig"
	    --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
	        --EvoBoard = "Jupiler Pro League"
	    --elseif (home == 2717 or home == 1236 or home == 2719 or home == 1927 or home == 2536 or home == 139 or home == 1923 or home == 2722 or home == 1238 or home == 1239 or home == 1924 or home == 1922 or home == 1240 or home == 1929 or home == 1241 or home == 2729 or home == 1237 or home == 138 or home == 1242 or home == 1243 or home == 1925 or home == 2702 or home == 5046 or home == 1926 or home == 2538 or home == 1244) and (away == 2717 or away == 1236 or away == 2719 or away == 1927 or away == 2536 or away == 139 or away == 1923 or away == 2722 or away == 1238 or away == 1239 or away == 1924 or away == 1922 or away == 1240 or away == 1929 or away == 1241 or away == 2729 or away == 1237 or away == 138 or away == 1242 or away == 1243 or away == 1925 or away == 2702 or away == 5046 or away == 1926 or away == 2538 or away == 1244) then
	        --EvoBoard = "Superliga Argentina"
	    --elseif (home == 209 or home == 180 or home == 5019 or home == 1329 or home == 406 or home == 407 or home == 2611 or home == 4370 or home == 413 or home == 414 or home == 4123 or home == 415 or home == 416 or home == 4210 or home == 4211 or home == 182 or home == 4212 or home == 219 or home == 420 or home == 1528) and (away == 209 or away == 180 or away == 5019 or away == 1329 or away == 406 or away == 407 or away == 2611 or away == 4370 or away == 413 or away == 414 or away == 4123 or away == 415 or away == 416 or away == 4210 or away == 4211 or away == 182 or away == 4212 or away == 219 or away == 420 or away == 1528) then
	        --EvoBoard = "Ligue 2"
		else
				EvoBoard = "Generic"
				--EvoBoard = "Default"
		end
	else
				--EvoBoard = "Default"
				EvoBoard = "Generic"
    end

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

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

local function trophy_rewrite(ctx, tournament_id)
	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
	   	 log("------- UEFA Champions League")
    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
	   	 log("------- UEFA Europa League")
	elseif tid == 34 or tid == 35 or tid == 36 or tid == 37 or tid == 38 or tid == 39 or tid == 40 or tid == 6800 or tid == 6801 or tid == 6802 or tid == 6803 or tid == 6804 or tid == 6805 or tid == 6806 or tid == 6807 or tid == 7200 or tid == 7201 or tid == 7202 or tid == 7203 or tid == 7204 or tid == 7205 or tid == 7206 or tid == 7207 or tid == 7400 or tid == 7600 or tid == 7800 or tid == 7801 or tid == 8000 or tid == 8001 then
		 log("------- FIFA World Cup")
	else
	   	 log("------- " .. EvoBoard)
	end
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 }