local fileroot = ".\\content\\CornerFlag"

function make_key(ctx, filename)
	tid = ctx.tournament_id
	home = ctx.home_team

    if tid == 52 then
		   CornerFlag = "J1 League"
	elseif home == 101 then
		   CornerFlag = "PremierLeague\\arsenal"
	elseif home == 102 then
	       CornerFlag = "PremierLeague\\chelsea"
	elseif home == 103 then
	       CornerFlag = "PremierLeague\\liverpool"
	elseif home == 105 then
	       CornerFlag = "PremierLeague\\west ham"
	elseif home == 106 then
	       CornerFlag = "PremierLeague\\newcastle united"
	elseif home == 107 then
	       CornerFlag = "PremierLeague\\aston villa"
	elseif home == 173 then
	       CornerFlag = "PremierLeague\\man city"
	elseif home == 177 then
	       CornerFlag = "PremierLeague\\everton"
	elseif home == 179 then
	       CornerFlag = "PremierLeague\\tottenham"
	elseif home == 204 then
	       CornerFlag = "PremierLeague\\leicester"
	elseif home == 207 then
	       CornerFlag = "PremierLeague\\soton"
	elseif home == 208 then
	       CornerFlag = "PremierLeague\\wolves"
	elseif home == 377 then
	       CornerFlag = "PremierLeague\\brighton"
	elseif home == 378 then
	       CornerFlag = "PremierLeague\\burnley"
	elseif home == 382 then
	       CornerFlag = "PremierLeague\\crystal palace"
	elseif home == 388 then
	       CornerFlag = "PremierLeague\\norwich"
	elseif home == 398 then
	       CornerFlag = "PremierLeague\\watford"
	elseif home == 4071 then
	       CornerFlag = "PremierLeague\\bournemouth"
	elseif home == 4194 then
	       CornerFlag = "PremierLeague\\sheffield utd"
	elseif home == 126 then
	       CornerFlag = "Bundesliga\\dortmund"
	elseif home == 128 then
	       CornerFlag = "Bundesliga\\leverkusen"
	elseif home == 185 then
	       CornerFlag = "Bundesliga\\werder bremen"
	elseif home == 225 then
	       CornerFlag = "Bundesliga\\m'gladbach"
	elseif home == 226 then
	       CornerFlag = "Bundesliga\\frankfurt"
	elseif home == 227 then
	       CornerFlag = "Bundesliga\\freiburg"
	elseif home == 232 then
	       CornerFlag = "Bundesliga\\wolfsburg"
	elseif home == 431 then
	       CornerFlag = "Bundesliga\\dusseldorf"
	elseif home == 436 then
	       CornerFlag = "Bundesliga\\mainz 05"
	elseif home == 4124 then
	       CornerFlag = "Bundesliga\\augsburg"
	elseif home == 4125 then
	       CornerFlag = "Bundesliga\\hertha bsc"
	elseif home == 4126 then
	       CornerFlag = "Bundesliga\\hoffenheim"
	elseif home == 4137 then
	       CornerFlag = "Bundesliga\\fc koln"
	elseif home == 4140 then
	       CornerFlag = "Bundesliga\\union berlin"
	elseif home == 4324 then
	       CornerFlag = "Bundesliga\\paderborn"
	elseif home == 5010 then
	       CornerFlag = "Bundesliga\\rb leipzig"
	elseif home == 121 then
	       CornerFlag = "Serie A\\ac milan"
	elseif home == 125 then
	       CornerFlag = "Serie A\\as roma"
	elseif home == 234 then
	       CornerFlag = "Serie A\\atalanta"
	elseif home == 186 then
	       CornerFlag = "Serie A\\bologna"
	elseif home == 320 then
	       CornerFlag = "Serie A\\cagliari"
	elseif home == 124 then
	       CornerFlag = "Serie A\\fiorentina"
	elseif home == 119 then
	       CornerFlag = "Serie A\\inter"
	elseif home == 122 then
	       CornerFlag = "Serie A\\lazio"
	elseif home == 123 then
	       CornerFlag = "Serie A\\parma"
	elseif home == 240 then
	       CornerFlag = "Serie A\\sampdoria"
	elseif home == 190 then
	       CornerFlag = "Serie A\\udinese"
	elseif home == 323 then
	       CornerFlag = "Serie A\\genoa"
	elseif home == 187 or home == 327 or home == 333 or home == 336 or home == 1919 or home == 4237 or home == 4923 then
	       CornerFlag = "Serie A\\Generic"
	elseif home == 4145 then
	       CornerFlag = "LaLiga\\alaves"
	elseif home == 258 then
	       CornerFlag = "LaLiga\\ath. bilbao"
	elseif home == 4146 then
	       CornerFlag = "LaLiga\\eibar"
	elseif home == 362 then
	       CornerFlag = "LaLiga\\getafe"
	elseif home == 1765 then
	       CornerFlag = "LaLiga\\granada"
	elseif home == 4272 then
	       CornerFlag = "LaLiga\\leganes"
	elseif home == 366 then
	       CornerFlag = "LaLiga\\levante"
	elseif home == 259 then
	       CornerFlag = "LaLiga\\espanyol"
	elseif home == 109 and (tid == 2 or tid == 4 or tid == 1026 or tid == 2050 or tid == 3074 or tid == 4098 or tid == 5122 or tid == 6146 or tid == 7170 or tid == 8149 or tid == 3 or tid == 1027  or tid == 2051 or tid == 3075 or tid == 4099 or tid == 5123 or tid == 6147 or tid == 7171 or tid == 8195) then
	       CornerFlag = "LaLiga\\real madrid\\UCL"
	elseif home == 109 then
	       CornerFlag = "LaLiga\\real madrid"
	elseif home == 172 then
	       CornerFlag = "LaLiga\\atl. madrid"
	elseif home == 261 then
	       CornerFlag = "LaLiga\\mallorca"
	elseif home == 263 then
	       CornerFlag = "LaLiga\\osasuna"
	elseif home == 265 then
	       CornerFlag = "LaLiga\\sevilla"
	elseif home == 194 then
	       CornerFlag = "LaLiga\\real betis"
	elseif home == 110 then
	       CornerFlag = "LaLiga\\valencia"
	elseif home == 266 then
	       CornerFlag = "LaLiga\\valladolid"
	elseif home == 196 then
	       CornerFlag = "LaLiga\\soceidad"
	elseif home == 195 then
	       CornerFlag = "LaLiga\\celta"
	elseif home == 267 then
	       CornerFlag = "LaLiga\\villareal"
	elseif tid == 20 then
	       CornerFlag = "Ligue 1"
	elseif tid == 81 then
	       CornerFlag = "Ligue 2"
	elseif home == 114 then
           CornerFlag = "Ligue 1\\paris"
	elseif home == 181 then
	       CornerFlag = "Ligue 1\\lyon"
	elseif home == 213 then
		   CornerFlag = "Ligue 1\\lille"
	elseif home == 243 then
	       CornerFlag = "Eredivise\\ado den haag"
	elseif home == 116 then
	       CornerFlag = "Eredivise\\ajax"
	elseif home == 242 then
	       CornerFlag = "Eredivise\\az"
	elseif home == 342 then
	       CornerFlag = "Eredivise\\emmen"
	elseif home == 117 then
	       CornerFlag = "Eredivise\\feyernord"
	elseif home == 345 then
	       CornerFlag = "Eredivise\\fortuna sittard"
	elseif home == 244 then
	       CornerFlag = "Eredivise\\groningen"
	elseif home == 245 then
	       CornerFlag = "Eredivise\\heerenven"
	elseif home == 349 then
	       CornerFlag = "Eredivise\\heracles"
	elseif home == 256 then
	       CornerFlag = "Eredivise\\pec zwolle"
	elseif home == 118 then
	       CornerFlag = "Eredivise\\psv"
	elseif home == 351 then
	       CornerFlag = "Eredivise\\sparta rotterdam"
	elseif home == 250 then
	       CornerFlag = "Eredivise\\twente"
	elseif home == 251 then
	       CornerFlag = "Eredivise\\utrecht"
	elseif home == 252 then
	       CornerFlag = "Eredivise\\vitesse"
	elseif home == 355 then
	       CornerFlag = "Eredivise\\vvv venlo"
	elseif home == 254 then
	       CornerFlag = "Eredivise\\waalwijk"
	elseif home == 255 then
	       CornerFlag = "Eredivise\\willem II"
    else
		   CornerFlag = nil
		
    end
    if tid then
       return string.format("%s:%s", CornerFlag, filename)
    end
end

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

function make_log(ctx)
    if CornerFlag ~= nil then
       logResult = CornerFlag
       log("-------- " .. logResult)
    end
end

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

return { init = init }