local BIReportV2 = {}

-- 所有上报事件

local EVENT_NAME_PRODUCTION_SALES_V2 = "client_production_sales_v2"				-- 产销
local EVENT_NAME_FIGHT_V2 = "client_fight_v2"									-- 玩法
local EVENT_NAME_LEVEL_UP_V2 = "client_level_up_v2"								-- 升级
local EVENT_NAME_OPERATION_V2 = "client_operation_v2"							-- 操作


BIReportV2.PRODUCTION_SALES_TYPE = {
	ITEM = "道具",
	CURRENCY = "货币"
}

BIReportV2.PRODUCTION_SALES_EVENT_TYPE = {
	USE = "获得",
	GET = "消耗"
}

BIReportV2.FIGHT_TYPE = {
	FIGHT_BEGIN = "开始",
	FIGHT_END = "结束"
}

BIReportV2.FIGHT_NAME = {
	[1] = "主线关卡",
	[2] = "日常副本",
	[3] = "爬塔",
	[4] = "世界BOSS",
	[5] = "精英挑战",
	[6] = "元素地牢",
	[18] = "竞技场",
}
BIReportV2.FIGHT_NAME_DUNGEON_GOLD = "金币副本"
BIReportV2.FIGHT_NAME_DUNGEON_MATERIAL = "材料副本"

BIReportV2.FIGHT_RESULT = {
	WIN = "胜利",
	FAIL = "失败",
	FINISH = "完成",
	QUIT = "退出",
	UNKNOW = "未知"
}

BIReportV2.OPERATION_TYPE = {
	CLICK = "点击",
	SHOW = "展示",
}

BIReportV2.LEVEL_UP_TYPE = {
	GET_PLAYER_EXP = "获取账号经验",
}

BIReportV2.OPERATION_UI_NAME = {
	LOGIN_UI = "登陆",
	FIRST_RECHARGE_PAGE_1 = "首充第一档",
	FIRST_RECHARGE_PAGE_2 = "首充第二档",
	FIRST_RECHARGE_PAGE_3 = "首充第三档",
	POP_CHAPTER_UI = "章节弹出礼包",
	ROUTINE_GIFT_1 = "新手礼包",
	ROUTINE_GIFT_2 = "日礼包",
	ROUTINE_GIFT_3 = "周礼包",
	ROUTINE_GIFT_4 = "月礼包",
	PRIVILEGE_CARD = "特权卡",
	PRIVILEGE_CARD_1 = "特权每日福利",
	PRIVILEGE_CARD_2 = "免广告",
	PRIVILEGE_CARD_3 = "月卡",
	PRIVILEGE_CARD_4 = "终身卡",
	PRIVILEGE_CARD_5 = "挑战征服卡",
	FUND_LEVEL = "成长基金",
	FUND_CHAPTER = "关卡基金",
	BOUNTY_COLLECTION = "宝物战令",
	TOWER_BOUNTY = "爬塔战令",
	SING_WEEK = "7日签到",
	SIGN_MONTH = "30日签到",
	ACT_SEVENDAY_TASK = "七天乐任务",
	ACT_SEVENDAY_GIFT = "七天乐礼包",
	ACT_SEVENDAY_TASK_2 = "七天乐任务第二期",
	ACT_SEVENDAY_GIFT_2 = "七天乐礼包第二期",
	ACT_SEVENDAY_LOOP_TASK_1 = "七日达标1循环任务",
	ACT_SEVENDAY_LOOP_GIFT_1 = "七日达标1循环礼包",
	ACT_SEVENDAY_LOOP_TASK_2 = "七日达标2循环任务",
	ACT_SEVENDAY_LOOP_GIFT_2 = "七日达标2循环礼包",
	ACT_SEVENDAY_LOOP_TASK_3 = "七日达标3循环任务",
	ACT_SEVENDAY_LOOP_GIFT_3 = "七日达标3循环礼包",
	SHOP_CHAPTER = "商店章节礼包",
	SHOP_DAILY_STORE = "每日商店",
	SHOP_GEM_STORE = "钻石礼包",
	SHOP_GOLD_STORE = "金币礼包",
	MAIN_SHOP = "商城",
	ACT_SUMMON_LOGIN = "卡池活动登录福利",
	ACT_SUMMON_UPGRADE_1 = "卡池活动英雄升级1",
	ACT_SUMMON_UPGRADE_2 = "卡池活动英雄升级2",
	ACT_SUMMON_GEM = "特惠礼包",
	ACT_SUMMON_RECHARGE = "连冲豪礼",
	SUMMON_MAIN = "普通召唤",
	SUMMON_ACT_1 = "召唤界面:电闪雷鸣",
	SUMMON_ACT_2 = "召唤界面:虎豹之争",
	GIFT_CHAIN_POP = "连锁礼包弹窗",
	ACT_SPRINT_NEW_SUMMON = "普通召唤新手冲刺活动版本2-加签到任务不改",
	ACT_SPRINT_NEW_BOX = "史诗芯魂宝箱新手冲刺活动版本2-加签到任务不改",
	ACT_SPRINT_LOOP_SUMMON = "普通召唤冲刺-循环版版本2",
	ACT_SPRINT_LOOP_BOX = "史诗芯魂冲刺-循环版版本2",
	ACT_SPRINT_LOOP_TREE = "钻石消耗冲刺-循环版版本2",
}

BIReportV2.UI_PATH_NAME = {

}

function BIReportV2:postProductionSales(productionType, eventType, id, num, getType)
	local args = {
		itemCategory = productionType,  -- 产销类型
		itemId = id, 					-- 产销物品id
		quantity = num,					-- 产销数量
		approach = getType,				-- 产销途径
		eventType = eventType,			-- 产销事件
	}
	BIReport:report(EVENT_NAME_PRODUCTION_SALES_V2, args)
end

function BIReportV2:postItemProductionSales(optType, itemId, itemNum, getType)
	if itemNum == 0 then
		return
	end
	self:postProductionSales(BIReportV2.PRODUCTION_SALES_TYPE.ITEM, optType, itemId, itemNum, getType)
end

function BIReportV2:postCurrencyProductionSales(optType, itemId, itemNum, getType)
	if itemNum == 0 then
		return
	end
	self:postProductionSales(BIReportV2.PRODUCTION_SALES_TYPE.CURRENCY, optType, itemId, itemNum, getType)
end

function BIReportV2:getFightName(battleType, id)
	local fightName = battleType
	if battleType == ModuleManager.BattleManager.BATTLE_TYPE.DUNGEON then
		local dungeonDailyType = DataManager.DungeonDailyData:getDungeonDailyTypeByChapterId(id)
		if dungeonDailyType == GConst.DungeonConst.DUNGEON_DAILY_TYPE.GOLD then
			fightName = BIReportV2.FIGHT_NAME_DUNGEON_GOLD
		elseif dungeonDailyType == GConst.DungeonConst.DUNGEON_DAILY_TYPE.MATERIAL then
			fightName = BIReportV2.FIGHT_NAME_DUNGEON_MATERIAL
		end
	else
		fightName = BIReportV2.FIGHT_NAME[battleType] or tostring(battleType)
	end
	return fightName
end

function BIReportV2:getFightResult(battleType, fightResult)
	if battleType == ModuleManager.BattleManager.BATTLE_TYPE.TOWER then
		return BIReportV2.FIGHT_RESULT.FINISH
	else
		if fightResult == BIReport.FIGHT_END_TYPE.WIN then
			return BIReportV2.FIGHT_RESULT.WIN
		elseif fightResult == BIReport.FIGHT_END_TYPE.FAIL then
			return BIReportV2.FIGHT_RESULT.FAIL
		elseif fightResult == BIReport.FIGHT_END_TYPE.QUIT then
			return BIReportV2.FIGHT_RESULT.QUIT
		else
			return BIReportV2.FIGHT_RESULT.UNKNOW
		end
	end
end

function BIReportV2:postFightBegin(battleType, id)
	local args = {
		playType = self:getFightName(battleType, id),
		playName = id,
		eventType = BIReportV2.FIGHT_TYPE.FIGHT_BEGIN
	}
	BIReport:report(EVENT_NAME_FIGHT_V2, args)
end

function BIReportV2:postFightEnd(battleType, id, fightResult, time, ext)
	local args = {
		playType = self:getFightName(battleType, id),
		playName = id,
		playResult = self:getFightResult(battleType, fightResult),
		ext1 = ext,
		playTime = time,
		eventType = BIReportV2.FIGHT_TYPE.FIGHT_END
	}
	BIReport:report(EVENT_NAME_FIGHT_V2, args)
end

function BIReportV2:postLevelUp(exp, getType, beforeLevel, afterLevel)
	local args = {
		exp = exp,
		approach = getType,
		beforeLevel = beforeLevel,
		afterLevel = afterLevel,
		eventType = BIReportV2.LEVEL_UP_TYPE.GET_PLAYER_EXP
	}
	BIReport:report(EVENT_NAME_LEVEL_UP_V2, args)
end

function BIReportV2:postOperation(uiName)
	if uiName == nil then
		return
	end
	local args = {
		operationName = uiName,
		eventType = BIReportV2.OPERATION_TYPE.CLICK
	}
	BIReport:report(EVENT_NAME_OPERATION_V2, args)
end

function BIReportV2:postOpenUI(uiPath)
	if uiPath == nil then
		return
	end
	local uiName = BIReportV2.UI_PATH_NAME[uiPath]
	if uiName == nil then
		return
	end
	self:postOperation(uiName)
end

return BIReportV2