local BIReport = {
	isNewPlayer = false
}

-- 客户端的所有的上报事件都要加"client_"前缀
local EVENT_NAME_TUTORIAL = "client_tutorial"
local EVENT_NAME_LUA_CRASH = "client_lua_crash"
local EVENT_NAME_OPEN_UI = "client_open_ui"

-- 所有需要上报的按钮点击事件
BIReport.CLICK_BTN_TYPE = {
	HOME = "Home",
	HERO = "Hero",
}

BIReport.ADS_OPT_TYPE = {
	CLICK = "Click",
	SUCCESS = "Success",
	REWARD_GET = "RewardGet",
}

BIReport.PAY_OPT_TYPE = {
	CLICK = "Click",
	BUY = "Buy",
	REWARD = "Reward",
	APPLE_REVIEW_REWARD = "AppleReviewReward",
	WHITELIST_REWARD = "WhitelistReward",
	CANCEL = "Cancel",
	FAILED = "Failed",
	INIT_SUC = "InitSuc",
	INIT_FAILED = "InitFailed",
}

BIReport.ACCOUNT_OPT_TYPE = {
	LOGIN_SUCCESS = "LoginSuccess",
	LOGIN_FAILED = "LoginFailed",
	CLICK_BIND = "ClickBind",
	BIND_SUCCESS = "BindSuccess",
	BIND_FAILED = "BindFailed",
	DELETE = "Delete",
	CLICK_CHANGE_ACCOUNT = "ClickChangeAccount",
	CHANGE_ACCOUNT_SUCCESS = "ChangeAccountSuccess",
	CHANGE_ACCOUNT_FAILED = "ChangeAccountFailed",
}

BIReport.CHAPTER_OPT_TYPE = {
	PASS = "Pass",
	BOX_OPEN = "BoxOpen",
}

BIReport.TASK_TYPE = {
	DAILY = "Daily",
}

BIReport.TASK_OPT_TYPE = {
	FINISH = "Finish",
	REWARD = "Reward",
}

BIReport.ITEM_GET_TYPE = {
	NONE = "None",
	NEW_PLAYER_INITIAL = "NewPlayerInitial",	-- 新玩家创号自带
	UPGRADE_HERO = "UpgradeHero",
	CHAPTER_FIGHT_START = "ChapterFightStart",
	CHAPTER_FIGHT_END = "ChapterFightEnd",
	CHAPTER_BOX = "ChapterBox",
	CROSS_DAY = "CrossDay",
	RECOVERY_TIME = "RecoveryTime",
	ADS_BUY_VIT = "AdsBuyVit",
	GEM_BUY_VIT = "GemBuyVit",
	ADS_BUY_ARENA_TICKET = "AdsBuyArenaTicket",
	GEM_BUY_ARENA_TICKET = "GemBuyArenaTicket",
	TASK_DAILY_REFRESH = "TaskDailyRefresh",
	TASK_DAILY_REWARD = "TaskDailyReward",
	BOUNTY_UNLOCK_LEVEL = "BountyUnlockLevel",
	BOUNTY_REWARD = "BountyReward",
	BOUNTY = "Bounty",
	ARENA_BOUNTY_UNLOCK_LEVEL = "ArenaBountyUnlockLevel",
	ARENA_BOUNTY_REWARD = "ArenaBountyReward",
	ARENA_BOUNTY = "ArenaBounty",
	IDLE_DROP = "IdleDrop",
	IDLE_QUICK_DROP = "IdleQuickDrop",
	MAIL = "Mail",
	MALL = "Mall",
	MALL_IDLE = "MallIdle", -- 常驻金币挂机礼包
	MALL_TREASURE = "MallTreasure", -- 常驻钻石礼包
	MALL_DAILY = "MallDaily", -- 每日特惠
	MALL_DAILY_RESET = "MallDailyReset",
	FIRST_RECHARGE = "FirstRecharge",
	COIN_GIFT = "CoinGift",
	BEGINNER_GIFT = "BeginnerGift",
	LEVEL_UP_GIFT = "LevelUpGift",
	ACT_CHAPTER_STORE = "ActChapterStore", -- 章节礼包
	SUMMON = "Summon",
	PLAYER_LV_UP = "PlayerLvUp",
	GOLD_PIG = "GoldPig",
	BATTLE_SKILL_REFRESH = "BattleSkillRefresh",
	GROWTH_FUND = "GrowthFund",
	GROW_UP_GIFT_NEW = "GrowUpGiftNew", -- 新成长礼包
	SEVEN_DAY_TASK = "SevenDayTask",
	SEVEN_DAY_STEP_REWARD = "SevenDayStepReward",
	DAILY_CHALLENGE = "DailyChallenge",              -- 每日挑战进入战斗扣体力
	DAILY_CHALLENGE_END = "DailyChallengeEnd",		 -- 每日挑战结算
	DAILY_CHALLENGE_RESET = "DailyChallengeReset",	 -- 每日挑战重置
	DAILY_CHALLENGE_TASK_REWARD = "DailyChallengeTaskReward",	-- 每日挑战任务奖励
	CDKEY = "Cdkey",
	DUNGEON_GOLD_CHALLENGE = "DungeonGoldChallenge",	-- 金币副本挑战
	DUNGEON_GOLD_END = "DungeonGoldEnd",	-- 金币副本结算
	DUNGEON_GOLD_SWEEP = "DungeonGoldSweep",	-- 金币副本扫荡
	DUNGEON_SHARDS_CHALLENGE = "DungeonShardsChallenge",	-- 碎片副本挑战
	DUNGEON_SHARDS_END = "DungeonShardsEnd",	-- 碎片副本结算
	DUNGEON_SHARDS_SWEEP = "DungeonShardsSweep",	-- 碎片副本扫荡
	ARENA_REMATCH_CD = "ArenaRematchCd",
	ARENA_REWARD = "ArenaReward",
	ARENA_AD_BOX_REWARD = "ArenaAdBoxReward",
	ARENA_GRADING_REWARD = "ArenaGradingReward",
	CHANGE_NAME = "ChangeName",	-- 重命名
	CHANGE_AVATAR = "ChangeAvatar",	-- 修改头像
	CHANGE_FRAME = "ChangeFrame",	-- 修改头像框
	INTRODUCTORY_GIFT = "IntroductoryGift",  -- 入门礼包
	ARENA_CHALLENGE = "ArenaChallenge",
	ARENA_SETTLEMENT = "ArenaSettlement",
	ARENA_GIFT = "ArenaGift",
	ACTIVITY_BOUNTY_REWARD = "ActivityBountyReward",
	ACTIVITY_BOUNTY_LEVEL = "ActivityBountyLevel",
	COLLECTION_HERO_REWARD = "CollectionHeroReward",
	DUNGEON_WEAPON_CHALLENGE = "DungeonWeaponChallenge",
	DUNGEON_WEAPON_END = "DungeonWeaponEnd",
	DUNGEON_WEAPON_SWEEP = "DungeonWeaponSweep",
	DUNGEON_ARMOR_CHALLENGE = "DungeonArmorChallenge",
	DUNGEON_ARMOR_END = "DungeonArmorEnd",
	DUNGEON_ARMOR_SWEEP = "DungeonArmorSweep",
	DUNGEON_ARMOR_STAR_REWARD = "DungeonArmorStarReward",
	DUNGEON_ARMOR_FUND_REWARD = "DungeonArmorFundReward",
	ARMOR_FUND = "ArmorFund",
	WEAPON_GIFT = "WeaponGift",
	ARMOR_GIFT = "ArmorGift",
	EQUIP_UPGRADE = "EquipUpgrade",
	ARMOR_UPGRADE = "ArmorUpgrade",
	OFFLINE_RECOVERY = "OfflineRecovery",
	ACT_SUMMER = "ActSummer",
	ACT_HERO_FUND = "ActHeroFund",
	ACT_BOSS_RUSH_FIGHT_START = "ActBossRushFightStart",
	ACT_BOSS_RUSH_FIGHT = "ActBossRushFight",
	ACT_BOSS_RUSH_FUND = "ActBossRushFund",
	ACT_BOSS_RUSH_SHOP = "ActBossRushShop",
	ACT_BOSS_RUSH_RANK = "ActBossRushRank",
	ACT_BOSS_RUSH_BUY_FUND = "ActBossRushBuyFund",
	ACT_FOURTEEN_DAY_BOUNTY = "ActFourteenDayBounty",
	ACT_FOURTEEN_DAY_TASK = "ActFourteenDayTask",
	ACT_FOURTEEN_DAY_EXCHANGE = "ActFourteenDayExchange",
	FOURTEEN_DAY_GIFT = "FourteenDayGift",
	FULL_MOON_HERO_GIFT = "FullMoonHeroGift",
	FULL_MOON_NEW_HERO_GIFT = "FullMoonNewHeroGift",
	FULL_MOON_SKIN_GIFT = "FullMoonSkinGift",
	DUNGEON_RUNE_START = "DungeonRuneStart",
	DUNGEON_RUNE_SETTLEMENT = "DungeonRuneSettlement",
	DUNGEON_RUNE_SWEEP = "DungeonRuneSweep",
	DUNGEON_RUNE_BUY_WING = "DungeonRunebuyWing",
	ACT_PVP_ENTER = "ActPvpEnter",
	ACT_PVP_REFRESH_HERO = "ActPvpRefreshHero",
	ACT_PVP_FIGHT_END = "ActPvpFightEnd",
	ACT_PVP_OVER_CD = "ActPvpOverCd",
	ACT_PVP_DAILY_REWARD = "ActPvpDailyReward",
	ACT_PVP_BOUNTY = "ActPvpBounty",
	ACT_PVP_BOUNTY_GIFT = "ActPvpBountyGift",
	ACT_PVP_RANK_REWARD = "ActPvpRankReward",
	ACT_PVP_BUY_BOUNTY_LEVEL = "ActPvpBuyBountyLevel",
	RUNES_QUENCHING = "RuneQuenching",
	RUNES_AUTO_QUENCHING = "RuneAutoQuenching",
	RUNES_GIFT = "RuneGift",
	TOURN_WAVE_BOUNTY_REWARD = "TournWaveBountyReward",
	TOURN_WAVE_BOUNTY_LEVEL = "TournWaveBountyLevel",
	TOURN_WAVE_RANK_REWARD = "TournWaveRankReward",
	TOURN_WAVE_GIFT = "TournWaveGift",
	TOURN_ARENA_BOUNTY_REWARD = "TournArenaBountyReward",
	TOURN_ARENA_BOUNTY_LEVEL = "TournArenaBountyLevel",
	TOURN_ARENA_RANK_REWARD = "TournArenaRankReward",
	TOURN_ARENA_GIFT = "TournArenaGift",
	FULL_MOON_TASK = "FullMoonTask",
	FULL_MOON_TASK_PROG_REWARD = "FullMoonTaskProgReward",
	FULL_MOON_SKIN_CHALLENGE_REWARD = "FullMoonSkinChallengeReward",
}

BIReport.ADS_CLICK_TYPE = {
	BATTLE_SKILL_REFRESH = "BattleSkillRefresh",
	AD_ENERGY = "AdEnergy",
	TASK_DAILY_REFRESH = "TaskDailyRefresh",
	TASK_DAILY_TASK = "TaskDailyTask",
	IDLE_QUICK_DROP = "IdleQuickDrop",
	ARENA_TICKET = "ArenaTicket",
	ARENA_REMATCH = "ArenaRematch",
	ARENA_AD_BOX = "ArenaAdBox",
	ARMOR_FUND_AD = "ArmorFundAd",
	DUNGEON_RUNE_REBIRTH = "DungeonRuneRebirth",
	ACT_PVP_AD_REFRESH_HERO = "ActPvpAdRefreshHero",
	ACT_PVP_AD_REMATCH = "ActPvpAdRematch",

	MALL_DAILY = "MallDaily",
	MALL_DAILY_RESET = "MallDailyReset",
	MALL_GOLD = "MallGold",
	MALL_TREASURE = "MallTreasure",
	MAIL = "Mail",
}

BIReport.FIGHT_OPT_TYPE = {
	START = "Start",
	END = "End",
	SELECT_SKILL_OPEN = "SelectSkillOpen",
	SELECT_SKILL = "SelectSkill",
	HERO_INFO = "HeroInfo",
	HERO_REPORT = "HeroReport",
}

BIReport.FIGHT_DEATH_TYPE = {
	SURVIVE = "Survive",
	ELITE_FAIL = "EliteFail",
	BOSS_FAIL = "BossFail",
	NORMAL_FAIL = "NormalFail",
}

BIReport.FIGHT_WAVE_END_TYPE = {
	WIN = "Win",
	FAIL = "Fail",
	QUIT = "Quit",
}

BIReport.BATTLE_TYPE = {
	["1"] = "Stage",
	["2"] = "DailyChallenge",
	["3"] = "DungeonGold",
	["4"] = "DungeonShards",
	["5"] = "Arena",
	["6"] = "DungeonWeapon",
	["7"] = "DungeonArmor",
	["8"] = "ActBossRush",
	["9"] = "DungeonRune",
	["10"] = "FullMoonSkin",
	["11"] = "ActPvp",
}

BIReport.GIFT_TYPE = {
	FIRST_RECHARGE = "FirstRecharge",
	COIN_GIFT = "CoinGift",
	BEGINNER_GIFT = "BeginnerGift",
	LEVEL_UP_GIFT = "LevelUpGift",
	BOUNTY = "Bounty",
	GOLD_PIG = "GoldPig",
	MALL_TREASURE = "MallTreasure",
	ACT_CHAPTER_STORE = "ActChapterStore",
	GROWTH_FUND = "GrowthFund",
	GROW_UP_GIFT_NEW = "GrowUpGiftNew",
	ARENA_BOUNTY = "ArenaBounty",
	INTRODUCTORY_GIFT = "IntroductoryGift",
	ARENA_GIFT = "ArenaGift",
	ARMOR_FUND = "ArmorFund",
	WEAPON_GIFT = "WeaponGift",
	ARMOR_GIFT = "ArmorGift",
	ACT_SUMMER = "ActSummer",
	ACT_HERO_FUND = "ActHeroFund",
	FOURTEEN_DAY_GIFT = "FourteenDayGift",
	ACT_PVP_BOUNTY_GIFT = "ActPvpBountyGift",
	FULL_MOON_HERO_GIFT = "FullMoonHeroGift",
	FULL_MOON_NEW_HERO_GIFT = "FullMoonNewHeroGift",
	FULL_MOON_SKIN_GIFT = "FullMoonSkinGift",
	RUNES_GIFT = "RunesGift",
	TOURN_WAVE_GIFT = "TournWaveGift",
	TOURN_ARENA_GIFT = "TournArenaGift",
}

BIReport.COIN_TYPE = {
	[1] = "Gold",
	[2] = "Gem",
}

BIReport.MAIL_OPT_TYPE = {
	OPEN = "Open",
	CLAIM = "Claim",
	CLICK = "Click",
}

BIReport.BOUNTY_OPT_TYPE = {
	BOUNTY_LEVEL_UP = "BountyLevelUp",
	BOUNTY_REWARD = "BountyReward",
	ARENA_BOUNTY_LEVEL_UP = "ArenaBountyLevelUp",
	ARENA_BOUNTY_REWARD = "ArenaBountyReward",
}

BIReport.HERO_OPT_TYPE = {
	UNLOCK = "Unlock",
	ACTIVE = "Active",
	LEVEL_UP = "LevelUp",
	FORMATION = "Formation",
}

BIReport.NETWORK_OPT_TYPE = {
	DISCONNECT = "disconnect",
	RECONNECT = "reconnect",
	ERROR_CODE = "errorCode",
	PD_DECODE_FAILED = "pdDecodeFailed",
	AUTH_FAILED = "authFailed",
}

BIReport.DIALY_CHALLENGE_OPT_TYPE = {
	TASK_STATE = "TaskState",
}

BIReport.MISCELLANEOUS_OPT_TYPE = {
	EVALUATE_OPEN = "EvaluateOpen",
	EVALUATE_CLOSE = "EvaluateClose",
	BATTLE_SNAP_SHOP_OPEN = "BattleSnapShopOpen",
}

BIReport.ARENA_OPT_TYPE = {
	CONSUME = "Consume",
	SETTLEMENT = "Settlement",
}

BIReport.PAY_UI_SHOW_TYPE = {
	LOGIN_POP = "LoginPop",
	TRIGGER_POP = "TriggerPop",
	CLICK_SHOW = "ClickShow",
	SHOP_SHOW = "ShopShow",
	ENTER_SHOW = "EnterShow",
}

BIReport.BOX_OPEN_BOX_TYPE = {
	SHOP = "Shop",
	ACTIVITY = "Activity",
}

BIReport.BOX_OPEN_OPEN_TYPE = {
	USE_KEY = "UseKey",
	USE_GEM = "UseGem",
	BOUNTY = "Bounty",
	ARENA_BOUNTY = "ArenaBounty",
}

BIReport.ACTIVITY_SUMMER = {
	TASK_REWARD = "TaskReward",
	BUY_LEVEL_UP = "BuyLevelUp",
}

BIReport.RUNES_FORMATION = {
	CHAPTER = "chapter",
}

-- b6
local EVENT_NAME_EXIT = "client_exit"
local EVENT_NAME_FIGHT = "client_fight"
local EVENT_NAME_CLICK_BTN = "client_click_btn"
local EVENT_NAME_ITEM_GET = "client_item_get"
local EVENT_NAME_ITEM_USE = "client_item_use"
local EVENT_NAME_COIN_GET = "client_coin_get"
local EVENT_NAME_COIN_USE = "client_coin_use"
local EVENT_NAME_AD_OPT = "client_ads_opt"
local EVENT_NAME_PAY_OPT = "client_pay_opt"
local EVENT_NAME_LOGIN_FINISH = "client_login_finish"
local EVENT_NAME_LOGIN = "client_login"
local EVENT_NAME_PING_SERVER = "client_ping_server"
local EVENT_NAME_ACCOUNT_OPT = "client_account_opt"
local EVENT_NAME_CHAPTER_OPT = "client_chapter_opt" -- 章节
local EVENT_NAME_VIT_USE = "client_vit_use"
local EVENT_NAME_VIT_GET = "client_vit_get"
local EVENT_NAME_DAILY_TASK = "client_daily_task"
local EVENT_NAME_MAIL_OPT = "client_mail_opt"
local EVENT_NAME_HERO_OPT = "client_hero_opt"
local EVENT_NAME_PLAYER_LV_UP = "client_player_lv_up"	-- 玩家升级
local EVENT_NAME_PAY_UI_SHOW = "client_pay_ui_show" -- 内购相关界面展示
local EVENT_NAME_BOUNTY_OPT = "client_bounty_opt" 	-- 通用战令事件(包括常规,竞技场等)
local EVENT_NAME_NETWORK_OPT = "client_network_opt" -- 网络操作
local EVENT_NAME_APPLOVIN_AD_REVENUE = "client_applovin_ad_revenue" -- applovin广告收入
local EVENT_NAME_IRONSOURCE_AD_REVENUE = "client_ironsource_ad_revenue" -- applovin广告收入
local EVENT_NAME_DAILY_CHALLENGE_OPT = "client_daily_challenge_opt"
local EVENT_NAME_ARENA_OPT = "client_arena_opt"-- 竞技场
local EVENT_NAME_MISCELLANEOUS_OPT = "event_name_miscellaneous_opt" -- 一些杂项
local EVENT_BOX_OPEN = "client_box_open"
local EVENT_ACT_OPT = "client_act_opt"
local EVENT_NAME_RUNES = "client_runes"

function BIReport:setIsNewPlayer(isNewPlayer)
	self.isNewPlayer = isNewPlayer
end

-- adjust
function BIReport:postAdjustSimpleTrackEvent(eventName)
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	if not eventName then
		return
	end
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAdjustSimpleTrackEvent(eventName)
end

function BIReport:postAdjustAdRevenueAppLovinMAX(revenue, networkName, adUnitIdentifier, placement)
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAdjustAdRevenueAppLovinMAX(revenue, networkName, adUnitIdentifier, placement)
end

function BIReport:updateAccountId(id)
	if id == nil then
		return
	end
	self:clearAccountId()
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:SetThinkingAnalyticsAccountId(tostring(id))
end

function BIReport:clearAccountId()
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:ClearThinkingAnalyticsAccountId()
end

function BIReport:report(name, args)
	self:printArgsStr(name, args)
	-- 内网dev包和编辑器模式不上报
	if Platform and Platform:getIsDevChannel() or EDITOR_MODE then
		return
	end

	-- 审核模式不上报
	if CS.BF.BFMain.IsShenhe then
		return
	end
	if args and type(args) == "table" then
		if DataManager and DataManager:getIsInitWithServer() then
			if DataManager.ChapterData then
				if args.max_level == nil then
					args.max_level = DataManager.ChapterData:getMaxChapterId()
				end
				if args.level_id == nil then
					args.level_id = DataManager.ChapterData:getChapterId()
				end
				if args.max_chapter == nil then
					args.max_chapter = DataManager.ChapterData:getNextChapter(DataManager.ChapterData:getMaxChapterId())
				end
			end
			if DataManager.BagData and DataManager.BagData.ItemData then
				args.gold = DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_GOLD)
				args.gem = DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_GEM)
				args.energy = DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_VIT)
			end
			if DataManager.PlayerData then
				args.player_level = DataManager.PlayerData:getLv()
			end

			local str, lv, atk, hp = DataManager.FormationData:getStageFormationBIStr()
			args.formation_atk = atk
			args.formation_hp = hp
			if DataManager.DungeonData then
				args.dungeon_progress = DataManager.DungeonData:getDungeonBIStr()
			end
			args.game_version = DataManager.PlayerData:getGameVersion()
		end
		args.current_version = CS.BF.BFMain.Instance.GameLaunchMgr:GetCurrentVersion()
		args.is_new_player = self.isNewPlayer
		args.device_unique_identifier = CS.UnityEngine.SystemInfo.deviceUniqueIdentifier
		CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostThinkingAnalyticsEvent(name, json.encode(args))
	else
		CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostThinkingAnalyticsEvent(name)
	end
end

-- 上报引导每一步
function BIReport:postTutorialStep(id)
	local level = DataManager.PlayerData:getLv()
	local args = {
		client_tutorial_id = id,
		level = level
	}
	self:report(EVENT_NAME_TUTORIAL, args)
end

-- Lua crash
function BIReport:postLuaCrash(logString, stackTrace)
	local msg = logString .. stackTrace
	if #msg > 2000 then
		msg = string.sub(msg, 1, 2000)
	end
	local args = {
		client_lua_crash_msg = msg,
	}
    self:report(EVENT_NAME_LUA_CRASH, args)
end

-- 上报界面打开
function BIReport:postOpenUI(uiName, childUI)
	if uiName == nil or uiName == "" then
		return
	end
	local args = {
		client_ui_name = uiName,
		client_ui_child_name = childUI,
	}
	self:report(EVENT_NAME_OPEN_UI, args)
end

-- 上报内购事件,单独处理,只上报到AF和FB,不上报数数
function BIReport:postPurchase(price, content, originOrderId, orderId)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核模式不上报
	if GFunc.isShenhe() then
		return
	end
	-- 白名单模式也不上报
	if GFunc.isInWhitelist() then
		return
	end
	-- 上报AF,AF的所有事件值都是String类型
	local args = {
		af_revenue = tostring(price),
		af_currency = "USD",
		af_quantity = "1",
		af_content_id = content,
		af_order_id = originOrderId,
		af_receipt_id = orderId
	}
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_purchase", json.encode(args))

	-- 上报FB的付费事件
	local fbArgs = {
		order_id = originOrderId,
		product_id = content
	}
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogPurchase(price, "USD", json.encode(fbArgs))

	-- 上报付费到adjust
	if Platform:isIosPlatform() then
		self:postAdjustSimpleTrackEvent("rumq9q")
	else
		self:postAdjustSimpleTrackEvent("xzqrsb")
	end
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAdjustRevenueTrackEvent("naoyh8", price, "USD")
end

-- 上报等级提升事件,单独处理,只上报到AF和FB,不上报数数
function BIReport:postFirstLoginEvent()
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核模式不上报
	if CS.BF.BFMain.IsShenhe then
		return
	end
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_first_login", json.encode({}))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_first_login", json.encode({}))
end

-- 上报广告播放提升事件,单独处理,只上报到AF和FB,不上报数数
function BIReport:postAdEvent()
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	local adCount = DataManager.PlayerData:getAdCount()
	if not adCount then
		return
	end
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_AdRewardAD", json.encode({}))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_AdRewardAD", json.encode({}))
	if not self.afPostAdCount then
		self.afPostAdCount = {
			[2] = true,
			[3] = true,
			[5] = true,
			[10] = true,
			[20] = true,
			[40] = true,
			[80] = true,
		}
	end

	if self.afPostAdCount[adCount] then
		local args = {}
		CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_AdRewardAD_" .. adCount, json.encode(args))
	end

	if not self.fbPostAdCount then
		self.fbPostAdCount = {
			[2] = true,
			[3] = true,
			[5] = true,
			[10] = true,
			[20] = true,
		}
	end

	if self.fbPostAdCount[adCount] then
		local args = {}
		CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_AdRewardAD_" .. adCount, json.encode(args))
	end
end

-- 上报进入章节事件,单独处理,只上报到AF和FB,不上报数数
function BIReport:postChapterEvent(chapter)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	if not chapter then
		return
	end
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_Level", json.encode({}))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_Level", json.encode({}))
	if not self.afPostChapter then
		self.afPostChapter = {
			[1] = true,
			[2] = true,
			[3] = true,
			[4] = true,
			[5] = true,
			[6] = true,
			[7] = true,
			[8] = true,
			[9] = true,
			[10] = true,
			[11] = true,
			[12] = true,
			[13] = true,
			[14] = true,
			[15] = true,
			[16] = true,
			[17] = true,
			[18] = true,
			[19] = true,
			[20] = true,
			[30] = true,
			[40] = true,
			[50] = true,
		}
	end
	if self.afPostChapter[chapter] then
		local args = {}
		CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_Chapter_" .. chapter, json.encode(args))
	end

	if not self.fbPostChapter then
		self.fbPostChapter = {
			[1] = true,
			[2] = true,
			[3] = true,
			[4] = true,
			[5] = true,
			[6] = true,
			[7] = true,
			[8] = true,
			[9] = true,
			[10] = true,
			[15] = true,
			[20] = true,
			[30] = true,
			[40] = true,
			[50] = true,
		}
	end

	if self.fbPostChapter[chapter] then
		local args = {}
		CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_Chapter_" .. chapter, json.encode(args))
	end
end

-- 上报获取任意x个英雄
function BIReport:postFirstGetHero(num)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	if not self.postHeroNum then
		self.postHeroNum = {
			[4] = true,
			[6] = true,
			[8] = true,
			[10] = true,
			[12] = true,
			[14] = true,
			[16] = true,
			[18] = true,
			[20] = true,
		}
	end

	if not self.postHeroNum[num] then
		return
	end
	local args = {}
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_herosum_" .. num, json.encode(args))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_herosum_" .. num, json.encode(args))
end

-- 上报英雄等级
function BIReport:postHeroLev(beforeLv, lv)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end

	local allHeroes = DataManager.HeroData:getAllHeroes()
	if not self.postHeroLevel then
		self.postHeroLevel = {
			[3] = true,
			[5] = true,
			[7] = true,
			[9] = true
		}
	end

	local temp = {}
	for heroid, heroEntity in pairs(allHeroes) do
		for heroLv, _ in pairs(self.postHeroLevel) do
			if heroEntity:getLv() >= heroLv then
				temp[heroLv] = (temp[heroLv] or 0) + 1
			end
		end
	end
	for heroLv, count in pairs(temp) do
		if heroLv > beforeLv and heroLv <= lv and count == 5 then
			local args = {}
			CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_hero4_lev" .. heroLv, json.encode(args))
			CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_hero4_lev" .. heroLv, json.encode(args))
		end
	end
end

-- 上报等级提升事件,单独处理,只上报到AF和FB,不上报数数
function BIReport:postLvEvent(beforeLv, nowLv)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	if not nowLv then
		return
	end
	if not self.postLV then
		self.postLV = {
			[1] = true,
			[2] = true,
			[3] = true,
			[5] = true,
			[10] = true,
			[15] = true,
			[20] = true,
			[30] = true,
			[40] = true,
			[50] = true,
			[60] = true,
			[70] = true,
			[80] = true,
		}
	end

	-- CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_grade", json.encode({}))
	-- CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_grade", json.encode({}))
	local reportLv
	for lv, _ in pairs(self.postLV) do
		if beforeLv < lv and nowLv >= lv then
			reportLv = lv
			break
		end
	end
	if not reportLv then
		return
	end
	local args = {}
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_grade_" .. reportLv, json.encode(args))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_grade_" .. reportLv, json.encode(args))
end

-- 上报部分档位首次付费
function BIReport:postFirstRechargeEvent(id)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	if not self.postRechargeID then
		self.postRechargeID = {
			[1] = false, -- 0.99
			[2] = false, -- 1.99
			[3] = true, -- 2.99
			[4] = false, -- 3.99
			[5] = true, -- 4.99
			[6] = false, -- 5.99
			[7] = false, -- 6.99
			[8] = false, -- 7.99
			[9] = false, -- 8.99
			[10] = true, -- 9.99
			[11] = false, -- 11.99
			[12] = false, -- 14.99
			[13] = true, -- 19.99
			[14] = false, -- 24.99
			[15] = true, -- 29.99
			[16] = true, -- 49.99
			[17] = false, -- 69.99
			[18] = false, -- 99.99
			[19] = false, -- 199.99
		}
	end

	if not self.postRechargeID[id] then
		return
	end
	local cfg = ConfigManager:getConfig("recharge")[id]
	if not cfg then
		return
	end
	local args = {}
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_package_" .. cfg.price, json.encode(args))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_package_" .. cfg.price, json.encode(args))
end

-- 上报24小时内部分章节第一次失败的用户
function BIReport:postFirstDayGradeFailEvent(chapterId)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	if not DataManager:getIsInCreate24Hour() then
		return
	end
	if not self.postChapterId then
		self.postChapterId = {
			[1] = true,
			[2] = true,
			[3] = true,
			[5] = true,
		}
	end

	if not self.postChapterId[chapterId] then
		return
	end
	local args = {}
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_24_grade_" .. chapterId .. "_fail", json.encode(args))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_24_grade_" .. chapterId .. "_fail", json.encode(args))
end

-- 上报24小时内部分英雄升级
function BIReport:postFirstDayHeroLevel(heroId)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	if not DataManager:getIsInCreate24Hour() then
		return
	end
	local heroEntity = DataManager.HeroData:getHeroById(heroId)
	if not heroEntity or heroEntity:getLv() > 2 then
		return
	end
	if not self.postHeroId then
		self.postHeroId = {
			[22001] = "24_blade_levelup",
			[32001] = "24_onion_levelup",
			[42001] = "24_iceheart_levelup",
		}
	end

	if not self.postHeroId[heroId] then
		return
	end
	local args = {}
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_" .. self.postHeroId[heroId], json.encode(args))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_" .. self.postHeroId[heroId], json.encode(args))
end

-- 上报24小时内开宝箱
function BIReport:postFirstDayOpenBox(count)
	-- 只有外网正式渠道真机包才上报
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	-- 审核/白名单模式不上报
	if CS.BF.BFMain.IsShenhe or CS.BF.BFMain.IsWhite then
		return
	end
	if not DataManager:getIsInCreate24Hour() then
		return
	end
	if not self.postBoxCount then
		self.postBoxCount = {
			[3] = true
		}
	end

	if not self.postBoxCount[count] then
		return
	end

	local args = {}
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostAppsflyerEvent("af_24_boxopen_3", json.encode(args))
	CS.BF.BFMain.Instance.SDKMgr.BFLoginSDKMgr.FBSdk:LogAppEvent("fb_24_boxopen_3", json.encode(args))
end

-- AF广告价值回传
function BIReport:logAppsFlyerAdRevenue(mediationNetwork, monetizationNetwork, eventRevenue, data)
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	if not mediationNetwork or not monetizationNetwork or not eventRevenue then
		return
	end
	local jsonStr = data and json.encode(data) or "{}"
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:LogAppsFlyerAdRevenue(mediationNetwork, monetizationNetwork, eventRevenue, jsonStr)
end

-- Firebase
function BIReport:postFirebaseLog(eventName, eventValue)
	if not Platform:getIsPublishChannel() or EDITOR_MODE then
		return
	end
	if not eventName or not eventValue then
		return
	end
	CS.BF.BFMain.Instance.SDKMgr.BFThirdReportSDKMgr:PostFireBaseEvent(eventName, json.encode(eventValue))
end

-- 以下为数数
function BIReport:printArgsStr(eventName, args)
	if not EDITOR_MODE then
		return
	end
	local tab = clone(args)
	tab.eventName = eventName
	Logger.log("============report %s===========", eventName)
	Logger.printTable(tab or {})
end

-- 开启游戏
function BIReport:postGameLogin(isFirstLogin)
	local args = {
		first_begin = isFirstLogin,
		-- LogType -- 进入类型，不处理
	}
	self:report(EVENT_NAME_LOGIN, args)
end

-- 登录完成
function BIReport:postGameLoginFinish()
	-- FirstBegin	是否是首次登陆
	-- DailyFirstBegin	是否当日首次登录
	-- LogType	进入类型
	-- PushID	推送id
	-- MaxLevel	已解锁最大关卡
	-- Duration	登录加载时长
	-- MyEquip	拥有装备
	-- MyCherish	拥有传家宝
	-- MyRunes	拥有符文
	-- MaxTrial	副本进度
	-- IsNew	是否是新用户
	local args = {
		-- is_daily_first = DataManager:getIsTodayFirstLogin(),
		-- is_first = DataManager:getIsFirstLogin(),
	}
	args.all_heroes = DataManager.HeroData:getAllHeroesBIStr()
	self:report(EVENT_NAME_LOGIN_FINISH, args)
end

-- 游戏退出
function BIReport:postGameExit()
	local args = {}
	self:report(EVENT_NAME_EXIT, args)
end

-- 进入战斗
function BIReport:postFightBegin(battleType, wave, chapterId, maxChapter, startTimes)
	-- wave -- 波次
	-- chapterId	进入关卡编号
	-- maxChapter	已解锁最大关卡
	-- startTimes	累计进入次数

	local args = {
		battle_type = BIReport.BATTLE_TYPE[battleType],
		event_type = BIReport.FIGHT_OPT_TYPE.START,
		wave_id = wave,
		chapter_id = chapterId,
		fight_max_chapter = maxChapter,
		start_times = startTimes,
	}
	if EDITOR_MODE then
		if not args.battle_type then
			Logger.logFatal("============report postFightBegin 没有battle_type 请检查===========")
		end
	end
	args.formation, args.famation_level = DataManager.FormationData:getStageFormationBIStr()
	self:report(EVENT_NAME_FIGHT, args)
end

function BIReport:postFightEnd(battleType, battleData, chapterId, wave, duration, totalTime, eliminateCount, chapterEliminateCount, type, deathType, startTimes, isFirstWin, isFianlStep, maxLinkCount)
	-- wave	进入关卡编号
	-- LevelType	进入关卡类型
	-- MaxLevel	已解锁最大关卡
	-- StartTimes	累计进入次数
	-- IsNew	是否是新用户

	local skillStr = GConst.EMPTY_STRING
	local skillNum = 0
	local skillMap = battleData:getSelectSkillMap()
	if skillMap then
		for skillId, info in pairs(skillMap) do
			skillStr = skillStr .. skillId .. "|"
			skillNum = skillNum + (info.count or 0)
		end
	end

	local args = {
		battle_type = BIReport.BATTLE_TYPE[battleType],
		event_type = BIReport.FIGHT_OPT_TYPE.END,
		wave_id = wave,
		chapter_id = chapterId,
		duration = duration,
		chapter_duration = totalTime,
		eliminate = eliminateCount,
		chapter_eleminate = chapterEliminateCount,
		skill = skillStr,
		skill_num = skillNum,
		type = type, -- "Win Fail Quit",
		death_type = deathType,
		start_times = startTimes,
		is_first_win = isFirstWin,
		isFianlStep = isFianlStep,
	}
	if EDITOR_MODE then
		if not args.battle_type then
			Logger.logFatal("============report postFightEnd 没有battle_type 请检查===========")
		end
	end

	args.formation, args.famation_level = DataManager.FormationData:getStageFormationBIStr()
	args.max_link_count = maxLinkCount

	self:report(EVENT_NAME_FIGHT, args)
end

function BIReport:postShowFightSkillSelect(battleType, battleData, skillList, chapterId, totalTime, wave)
	local skillNum = 0
	local skillMap = battleData:getSelectSkillMap()
	if skillMap then
		for skillId, info in pairs(skillMap) do
			skillNum = skillNum + (info.count or 0)
		end
	end

	local skillStr = GConst.EMPTY_STRING
	if skillList then
		for _, skillId in ipairs(skillList) do
			skillStr = skillStr .. skillId .. "|"
		end
	end

	local args = {
		battle_type = BIReport.BATTLE_TYPE[battleType],
		event_type = BIReport.FIGHT_OPT_TYPE.SELECT_SKILL_OPEN,
		wave_id = wave,
		chapter_id = chapterId,
		chapter_duration = totalTime,
		skill = skillStr,
		skill_num = skillNum,
	}
	if EDITOR_MODE then
		if not args.battle_type then
			Logger.logFatal("============report postShowFightSkillSelect 没有battle_type 请检查===========")
		end
	end
	self:report(EVENT_NAME_FIGHT, args)
end

function BIReport:postFightSkillSelect(battleType, battleData, skillList, chapterId, totalTime, wave)
	local skillNum = 0
	local skillMap = battleData:getSelectSkillMap()
	if skillMap then
		for skillId, info in pairs(skillMap) do
			skillNum = skillNum + (info.count or 0)
		end
	end

	local skillStr = GConst.EMPTY_STRING
	if skillList then
		for _, skillId in ipairs(skillList) do
			skillStr = skillStr .. skillId .. "|"
		end
	end

	local args = {
		battle_type = BIReport.BATTLE_TYPE[battleType],
		event_type = BIReport.FIGHT_OPT_TYPE.SELECT_SKILL,
		wave_id = wave,
		chapter_id = chapterId,
		chapter_duration = totalTime,
		skill = skillStr,
		skill_num = skillNum,
	}
	if EDITOR_MODE then
		if not args.battle_type then
			Logger.logFatal("============report postFightSkillSelect 没有battle_type 请检查===========")
		end
	end
	self:report(EVENT_NAME_FIGHT, args)
end

function BIReport:postFightHeroInfo(battleType, arkFormation)
	if not arkFormation then
		return
	end
	local heroInfo = {}
	for matchType, heroEntity in pairs(arkFormation) do
		if heroEntity then
			local unit = {
				id = heroEntity:getCfgId(),
				level = heroEntity:getLv(),
				atk = heroEntity:getAtk(),
				hp = heroEntity:getHp(),
			}
			table.insert(heroInfo, unit)
		end
	end
	local args = {
		battle_type = BIReport.BATTLE_TYPE[battleType],
		event_type = BIReport.FIGHT_OPT_TYPE.HERO_INFO,
		hero_info = json.encode(heroInfo)
	}
	if EDITOR_MODE then
		if not args.battle_type then
			Logger.logFatal("============report postFightSkillSelect 没有battle_type 请检查===========")
		end
	end
	self:report(EVENT_NAME_FIGHT, args)
end

function BIReport:postFightHeroReport(battleType, atkReport)
	if not atkReport then
		return
	end
	local args = {
		battle_type = BIReport.BATTLE_TYPE[battleType],
		event_type = BIReport.FIGHT_OPT_TYPE.HERO_REPORT,
		atk_report =  json.encode(atkReport)
	}
	if EDITOR_MODE then
		if not args.battle_type then
			Logger.logFatal("============report postFightSkillSelect 没有battle_type 请检查===========")
		end
	end
	self:report(EVENT_NAME_FIGHT, args)
end

-- 首页按钮点击
function BIReport:postHomeBtnCilck(clickType)
	local args = {
		event_type = clickType,
		type = BIReport.CLICK_BTN_TYPE[clickType],
		chapter_id = DataManager.ChapterData:getChapterId()
	}
	self:report(EVENT_NAME_CLICK_BTN, args)
end

function BIReport:postChapterOpenBox(chapterId, wave, rewards)
	local rewardStr = GFunc.getRewardsStr(rewards)
	local args = {
		box_level = wave,
		rewards = rewardStr,
		chapter_id = chapterId,
		event_type = BIReport.CHAPTER_OPT_TYPE.BOX_OPEN
	}
	self:report(EVENT_NAME_CHAPTER_OPT, args)
end

-- 道具获取
function BIReport:postItemGet(num, itemId, getType)
	-- Item	道具id
	-- Type	获得方式
	-- MaxLevel	最大关卡
	-- ItemNum	获取道具数量
	-- ItemAll	获取后道具数量
	-- IsNew	是否是新用户
	local allNum = DataManager.BagData.ItemData:getItemNumById(itemId)
	local args = {
		item_value = num,
		item_id = itemId,
		item_all_value = allNum,
		type = getType,
	}
	self:report(EVENT_NAME_ITEM_GET, args)
end

-- 道具使用
function BIReport:postItemUse(num, itemId, getType)
	-- Item	道具id
	-- Type	消耗方式
	-- MaxLevel	最大关卡
	-- ItemNum	消耗道具数量
	-- ItemAll	消耗后道具数量
	-- IsNew	是否是新用户
	local allNum = DataManager.BagData.ItemData:getItemNumById(itemId)
	local args = {
		item_value = num,
		item_id = itemId,
		item_all_value = allNum,
		type = getType,
	}
	self:report(EVENT_NAME_ITEM_USE, args)
end

-- 体力获得
function BIReport:postVitGet(num, getType, vitAll)
	-- Type	获得类型	获得体力时	String	Ads=广告、Gold=金币 、Time=时间恢复 、Stores=商品恢复
	-- 	IsNew	是否是新用户		Boolean	是否为当天新用户，True = 是，False = 否
	-- 	EnergyNum	当前体力数		Int	获得体力数量
	-- 	MaxChapter	最大章节		Int	已解锁的最大章节
	local args = {
		type = getType,
		vit_num = num,
		vit_all = vitAll or DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_VIT),
	}
	self:report(EVENT_NAME_VIT_GET, args)
end

-- 体力使用
function BIReport:postVitUse(num, getType)
	-- EnergyNum	当前体力数	减少体力时	Int	使用体力数量
	-- 	IsNew	是否是新用户		Boolean	是否为当天新用户，True = 是，False = 否
	-- 	MaxChapter	最大章节		Int	已解锁的最大章节
	local args = {
		type = getType,
		vit_num = num,
		vit_all = DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_VIT),
	}
	self:report(EVENT_NAME_VIT_USE, args)
end

-- 点击广告按钮
function BIReport:postAdClick(adsType)
	local args = {
		ad_type = adsType,
		event_type = BIReport.ADS_OPT_TYPE.CLICK,
	}
	self:report(EVENT_NAME_AD_OPT, args)
end

-- 广告播放视频成功
function BIReport:postAdPlaySuccess(adsType)
	local args = {
		ad_type = adsType,
		event_type = BIReport.ADS_OPT_TYPE.SUCCESS,
	}
	self:report(EVENT_NAME_AD_OPT, args)
end

-- 广告奖励发放成功
function BIReport:postAdRewardGet(adsType)
	local args = {
		ad_type = adsType,
		event_type = BIReport.ADS_OPT_TYPE.REWARD_GET,
	}
	self:report(EVENT_NAME_AD_OPT, args)
end

-- 支付sdk初始化成功
function BIReport:postPayInitSuccess()
	local args = {
		event_type = BIReport.PAY_OPT_TYPE.INIT_SUC,
	}
	self:report(EVENT_NAME_PAY_OPT, args)
end

-- 支付sdk初始化失败
function BIReport:postPayInitFailed(failedDesc)
	local args = {
		pay_failed_desc = failedDesc or GConst.EMPTY_STRING,
		event_type = BIReport.PAY_OPT_TYPE.INIT_FAILED,
	}
	self:report(EVENT_NAME_PAY_OPT, args)
end

-- 点击商品购买按钮
function BIReport:postPayClick(giftType, id, rechargeId)
	local args = {
		gift_type = giftType,
		commodity_id = id,
		recharge_id = rechargeId,
		event_type = BIReport.PAY_OPT_TYPE.CLICK,
	}
	self:report(EVENT_NAME_PAY_OPT, args)
end

-- 跳转购买界面
function BIReport:postPayTurn(giftType, id, rechargeId)
	local args = {
		gift_type = giftType,
		commodity_id = id,
		recharge_id = rechargeId,
		event_type = BIReport.PAY_OPT_TYPE.BUY,
	}
	self:report(EVENT_NAME_PAY_OPT, args)
end

-- 取消购买
function BIReport:postPayCancel(productId, orderId, rechargeId, giftType, id)
	local args = {
		pay_product_id = productId,
		pay_order_id = orderId,
		recharge_id = rechargeId,
		gift_type = giftType,
		commodity_id = id,
		event_type = BIReport.PAY_OPT_TYPE.CANCEL,
	}
	self:report(EVENT_NAME_PAY_OPT, args)
end

-- 购买失败
function BIReport:postPayFailed(productId, orderId, rechargeId, failedType, giftType, id)
	local args = {
		pay_product_id = productId,
		pay_order_id = orderId,
		recharge_id = rechargeId,
		pay_failed_type = failedType,
		gift_type = giftType,
		commodity_id = id,
		event_type = BIReport.PAY_OPT_TYPE.FAILED,
	}
	self:report(EVENT_NAME_PAY_OPT, args)
end

-- -- 获得购买物品
function BIReport:postPayGet(giftType, id, rechargeId, orderId, originOrderId, buyNum, rewards)
	local args = {
		gift_type = giftType,
		commodity_id = id,
		buy_num = buyNum,
		origin_order_id = tostring(originOrderId),
		recharge_id = rechargeId,
		event_type = BIReport.PAY_OPT_TYPE.REWARD,
	}
	if GFunc.isShenhe() then
		args.event_type = BIReport.PAY_OPT_TYPE.APPLE_REVIEW_REWARD
	elseif GFunc.isInWhitelist() then
		args.event_type = BIReport.PAY_OPT_TYPE.WHITELIST_REWARD
	end
	self:report(EVENT_NAME_PAY_OPT, args)

	if EDITOR_MODE then
		if not giftType or not id or not rechargeId then
			local params = {
				content = "BI Report postPayGet has no basic params",
				boxType = GConst.MESSAGE_BOX_TYPE.MB_OK,
				okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK),
			}
			GFunc.showMessageBox(params)
			Logger.log("BI Report postPayGet has no basic params")
		end
	end
end

-- 登录成功
function BIReport:postAccountLoginFinish(loginType)
	local args = {
		login_type = loginType,
		event_type = BIReport.ACCOUNT_OPT_TYPE.LOGIN_SUCCESS,
	}
	self:report(EVENT_NAME_ACCOUNT_OPT, args)
end

-- 登录失败
function BIReport:postAccountLoginFailed(loginType, reason)
	local args = {
		login_type = loginType,
		login_failed_desc = reason,
		event_type = BIReport.ACCOUNT_OPT_TYPE.LOGIN_FAILED,
	}
	self:report(EVENT_NAME_ACCOUNT_OPT, args)
end


-- 上报ping服务器地址情况
function BIReport:postPingServer(address, time, resultType)
	local args = {
		address = address,
		time = time,
		type = resultType
	}
	self:report(EVENT_NAME_PING_SERVER, args)
end

-- 钻石增加
function BIReport:postGemGet(num, getType, itemId)
	-- CoinNum	代币数量	增加代币时	Int	获得代币数量
	-- Type	获得类型		String	广告=Ads、商店宝箱=Box、关卡宝箱=LevelBox、关卡奖励=LevelReward、
	-- CoinsType	代币类型		String	Gold=金币、Gems=钻石
	-- IsNew	是否是新用户		Boolean	是否为当天新用户，True = 是，False = 否
	-- MaxChapter	最大章节		Int	已解锁的最大章节
	local args = {
		type = getType,
		coin_num = num,
		coin_type = BIReport.COIN_TYPE[itemId],
		coin_all = DataManager.BagData.ItemData:getItemNumById(itemId),
	}
	self:report(EVENT_NAME_COIN_GET, args)
end

-- 钻石使用
function BIReport:postGemUse(num, getType, itemId)
	-- CoinNum	代币数量	减少代币时	Int	使用代币数量
	-- Type	使用类型		String	Box=开启宝箱、复活=Revive、天赋升级=Talent、Equip=装备升级
	-- CoinsType	代币类型		String	Gold=金币、Gems=钻石
	-- IsNew	是否是新用户		Boolean	是否为当天新用户，True = 是，False = 否
	-- MaxChapter	最大章节		Int	已解锁的最大章节
	local args = {
		type = getType,
		coin_num = num,
		coin_type = BIReport.COIN_TYPE[itemId],
		coin_all = DataManager.BagData.ItemData:getItemNumById(itemId),
	}
	self:report(EVENT_NAME_COIN_USE, args)
end

function BIReport:postDailyTaskFinish(taskType, cfgId, taskId, refresh)
	local args = {
		task_type = taskType,
		task_id = taskId,
		cfg_id = cfgId,
		task_refresh = refresh,
		event_type = BIReport.TASK_OPT_TYPE.FINISH,
	}
	self:report(EVENT_NAME_DAILY_TASK, args)
end

-- 邮箱
function BIReport:postMailOpen(mailId)
	-- IsNew	是否是新用户
	-- MaxLevel	最大关卡
	-- Email_ID	邮件编号

	local args = {
		mail_id = mailId,
		event_type = BIReport.MAIL_OPT_TYPE.OPEN,
	}
	self:report(EVENT_NAME_MAIL_OPT, args)
end

function BIReport:postMailClaim(mailId)
	-- IsNew	是否是新用户
	-- MaxLevel	最大关卡
	-- Email_ID	邮件编号

	local args = {
		mail_id = mailId,
		event_type = BIReport.MAIL_OPT_TYPE.CLAIM,
	}
	self:report(EVENT_NAME_MAIL_OPT, args)
end

function BIReport:postMailClick(mailId)
	-- Email_ID	邮件编号
	local args = {
		mail_id = mailId,
		event_type = BIReport.MAIL_OPT_TYPE.CLICK,
	}
	self:report(EVENT_NAME_MAIL_OPT, args)
end

function BIReport:postAccountDelete(loginType)
	local args = {
		login_type = loginType,
		event_type = BIReport.ACCOUNT_OPT_TYPE.DELETE,
	}
	self:report(EVENT_NAME_ACCOUNT_OPT, args)
end

function BIReport:postAccountBindClick(loginType)
	local args = {
		login_type = loginType,
		event_type = BIReport.ACCOUNT_OPT_TYPE.CLICK_BIND,
	}
	self:report(EVENT_NAME_ACCOUNT_OPT, args)
end

function BIReport:postAccountBindFinish(loginType, success)
	local args = {
		login_type = loginType,
		event_type = success and BIReport.ACCOUNT_OPT_TYPE.BIND_SUCCESS or BIReport.ACCOUNT_OPT_TYPE.BIND_FAILED,
	}
	self:report(EVENT_NAME_ACCOUNT_OPT, args)
end

function BIReport:postAccountChangeClick(loginType)
	local args = {
		login_type = loginType,
		event_type = BIReport.ACCOUNT_OPT_TYPE.CLICK_CHANGE_ACCOUNT,
	}
	self:report(EVENT_NAME_ACCOUNT_OPT, args)
end

function BIReport:postAccountChangeFinish(loginType, success)
	local args = {
		login_type = loginType,
		event_type = success and BIReport.ACCOUNT_OPT_TYPE.CHANGE_ACCOUNT_SUCCESS or BIReport.ACCOUNT_OPT_TYPE.CHANGE_ACCOUNT_FAILED,
	}
	self:report(EVENT_NAME_ACCOUNT_OPT, args)
end

function BIReport:postHeroOpt(heroId, optType)
	local heroEntity = DataManager.HeroData:getHeroById(heroId)
	if not heroEntity then
		return
	end

	local args = {
		hero_id = heroId,
		level = heroEntity:getLv(),
		event_type = optType
	}
	args.formation = DataManager.FormationData:getStageFormationBIStr()

	self:report(EVENT_NAME_HERO_OPT, args)
end

function BIReport:postPlayerLvUp(fromLevel, toLevel)
	local args = {
		player_level_from = fromLevel,
		player_level = toLevel,
	}
	self:report(EVENT_NAME_PLAYER_LV_UP, args)
end

-- 内购相关界面展示,包括弹出/主动打开(如果是打开商城页签,钻石礼包只上报id2,章节礼包只上报首个可购买章节id)
-- giftType为BIReport.GIFT_TYPE
function BIReport:postPayUIShow(giftType, giftId, showType)
	local args = {
		gift_type = giftType,
		commodity_id = giftId,
		show_type = showType
	}
	self:report(EVENT_NAME_PAY_UI_SHOW, args)
end

function BIReport:postBountyLevelUp(bountyType, level, exp, season)
	local args = {
		event_type = BIReport.BOUNTY_OPT_TYPE.BOUNTY_LEVEL_UP,
		season = season,
		level = level,
		exp = exp,
		bounty_type = bountyType,
	}
	self:report(EVENT_NAME_BOUNTY_OPT, args)
end

function BIReport:postBountyReward(bountyType, level, exp, season, rewardLevelId, isPro)
	local args = {
		event_type = BIReport.BOUNTY_OPT_TYPE.BOUNTY_REWARD,
		season = season,
		level = level,
		exp = exp,
		bounty_type = bountyType,
		bounty_level_id = rewardLevelId,
		is_pro = isPro,
	}
	self:report(EVENT_NAME_BOUNTY_OPT, args)
end

function BIReport:postArenaBountyLevelUp(bountyType, level, exp, season)
	local args = {
		event_type = BIReport.BOUNTY_OPT_TYPE.ARENA_BOUNTY_LEVEL_UP,
		season = season,
		level = level,
		exp = exp,
		bounty_type = bountyType,
	}
	self:report(EVENT_NAME_BOUNTY_OPT, args)
end

function BIReport:postArenaBountyReward(bountyType, level, exp, season, rewardLevelId, isPro)
	local args = {
		event_type = BIReport.BOUNTY_OPT_TYPE.ARENA_BOUNTY_REWARD,
		season = season,
		level = level,
		exp = exp,
		bounty_type = bountyType,
		bounty_level_id = rewardLevelId,
		is_pro = isPro,
	}
	self:report(EVENT_NAME_BOUNTY_OPT, args)
end

function BIReport:postNetWorkOpt(optType, uiName, errorCode, disconnectTime)
	local args = {
		event_type = optType,
		ui_name = uiName,
		error_code = errorCode,
		disconnect_time = disconnectTime
	}
	self:report(EVENT_NAME_NETWORK_OPT, args)
end

function BIReport:postAppLovinAdRevenue(msg)
	local args = json.decode(msg) or {}
	if args.revenue then
		self:postAdjustAdRevenueAppLovinMAX(args.revenue, args.network_name or GConst.EMPTY_STRING, args.ad_unit_identifier or GConst.EMPTY_STRING, args.placement or GConst.EMPTY_STRING)
		local args2 = {
			ad_platform = "applovin",
			ad_source = args.network_name,
			ad_unit_name = args.ad_unit_identifier,
			ad_format = args.ad_format,
			currency = "USD",
			value = args.revenue,
		}
		self:postFirebaseLog("ad_impression", args2)
		self:logAppsFlyerAdRevenue(3, args.network_name, args.revenue, args)
		-- 最后上报数数，因为数数会给args里面增加一些字段
		self:report(EVENT_NAME_APPLOVIN_AD_REVENUE, args)
	end
end

function BIReport:postIronSourceAdRevenue(msg)
	local args = json.decode(msg) or {}
	if args.revenue then
		local args2 = {
			ad_platform = "ironSource",
			ad_source = args.network_name,
			ad_unit_name = args.ad_unit_identifier,
			ad_format = args.ad_format,
			currency = "USD",
			value = args.revenue
		}
		self:postFirebaseLog("ad_impression", args2)
		self:logAppsFlyerAdRevenue(2, args.network_name, args.revenue, args)
		-- 最后上报数数，因为数数会给args里面增加一些字段
		self:report(EVENT_NAME_IRONSOURCE_AD_REVENUE, args)
	end
end

-- 竞技场进入消耗上报
function BIReport:postArenaConsume(gradingId, todayConsume)
	local args = {
		event_type = BIReport.ARENA_OPT_TYPE.CONSUME,
		grading_id = gradingId,
		today_consume = todayConsume,
	}
	self:report(EVENT_NAME_ARENA_OPT, args)
end

-- 竞技场结算数据上报
function BIReport:postArenaSettlement(gradingId, round, winRate, win)
	local args = {
		event_type = BIReport.ARENA_OPT_TYPE.SETTLEMENT,
		grading_id = gradingId,
		round = round,
		win_rate = winRate,
		win = win,
	}
	self:report(EVENT_NAME_ARENA_OPT, args)
end

function BIReport:postDailyChallengeTaskState(completedCount, taskInfo)
	local args = {
		event_type = BIReport.DIALY_CHALLENGE_OPT_TYPE.TASK_STATE,
		task_completed_count = completedCount,
		task_info = json.encode(taskInfo)
	}
	self:report(EVENT_NAME_DAILY_CHALLENGE_OPT, args)
end

function BIReport:postNetError(pbName, code, reqData, pbData)
	local msg = GConst.EMPTY_STRING
	if pbData then
		msg = json.encode(pbData)
		if msg and #msg > 2000 then
			msg = string.sub(msg, 1, 2000)
		end
	end

	local args = {
		event_type = BIReport.NETWORK_OPT_TYPE.ERROR_CODE,
		pb_name = pbName,
		ui_name = UIManager:getTopUIIndex(),
		error_code = code,
		req_data = reqData,
		msg = msg,
	}
	self:report(EVENT_NAME_NETWORK_OPT, args)
end

function BIReport:postPbDecodefailed(pbName, reqData)
	local args = {
		event_type = BIReport.NETWORK_OPT_TYPE.PD_DECODE_FAILED,
		pb_name = pbName,
		ui_name = UIManager:getTopUIIndex(),
		req_data = reqData
	}
	self:report(EVENT_NAME_NETWORK_OPT, args)
end

function BIReport:postPbAuthfailed(pbName, lastLoginInfo, authFailToLogin)
	local args = {
		event_type = BIReport.NETWORK_OPT_TYPE.AUTH_FAILED,
		pb_name = pbName,
		ui_name = UIManager:getTopUIIndex(),
		lastLoginInfo = lastLoginInfo,
		authFailToLogin = authFailToLogin
	}
	self:report(EVENT_NAME_NETWORK_OPT, args)
end

function BIReport:postRateClose(rateStar)
	local args = {
		event_type  = BIReport.MISCELLANEOUS_OPT_TYPE.EVALUATE_CLOSE,
		rate_star = rateStar,
	}
	self:report(EVENT_NAME_MISCELLANEOUS_OPT, args)
end

function BIReport:postRateOpen()
	local args = {
		event_type  = BIReport.MISCELLANEOUS_OPT_TYPE.EVALUATE_OPEN,
	}
	self:report(EVENT_NAME_MISCELLANEOUS_OPT, args)
end

function BIReport:postBatttleSnapshotOpen()
	local args = {
		event_type  = BIReport.MISCELLANEOUS_OPT_TYPE.BATTLE_SNAP_SHOP_OPEN,
	}
	self:report(EVENT_NAME_MISCELLANEOUS_OPT, args)
end

function BIReport:postPbAuthfailed(pbName, lastLoginInfo, authFailToLogin)
	local args = {
		event_type = BIReport.NETWORK_OPT_TYPE.AUTH_FAILED,
		pb_name = pbName,
		ui_name = UIManager:getTopUIIndex(),
		lastLoginInfo = lastLoginInfo,
		authFailToLogin = authFailToLogin
	}
	self:report(EVENT_NAME_NETWORK_OPT, args)
end

function BIReport:postBoxOpen(id, boxType, openType, box_level, rewards, box_count)
	local args = {
		box_type = boxType,
		open_type = openType,
		box_item_id = id,
		box_level = box_level,
		box_count = box_count,
		rewards_str = GFunc.getItemRewardsStr(rewards)
	}
	self:report(EVENT_BOX_OPEN, args)
end

function BIReport:postActOpt(event_type, actId, level, exp, buyLevelCost)
	local args = {
		event_type = event_type,
		act_id = actId,
		cur_level = level,
		cur_exp = exp,
		buy_level_cost = buyLevelCost,
	}
	self:report(EVENT_ACT_OPT, args)
end

function BIReport:postRunes(event_type, runes)
	local args = {
		event_type = event_type,
		runes = runes
	}
	self:report(EVENT_NAME_RUNES, args)
end

return BIReport