local FormationManager = class("FormationManager", BaseModule)

-- 主线编队
function FormationManager:upHeroToStageFormation(heroId, matchType)
	local formation = DataManager.FormationData:getStageFormation()
	if formation[matchType] == heroId then
		return
	end
	local args = {
		id = heroId
	}
	self:sendMessage(ProtoMsgType.FromMsgEnum.HeroPutOnReq, args, {}, self.upHeroToStageFormationFinish)
end

function FormationManager:upHeroToStageFormationFinish(result)
	if result.err_code == GConst.ERROR_STR.SUCCESS then
		DataManager.FormationData:init(result)
		DataManager.HeroData:setDirty()

		local data = {}
		data.formation, data.formation_lv, data.formation_atk, data.formation_hp = DataManager.FormationData:getStageFormationBIStr()
		data.formation_lv = nil
		CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
		if result.reqData then
			BIReport:postHeroOpt(result.reqData.id, BIReport.HERO_OPT_TYPE.FORMATION)
		end
	end
end

-- 竞技场编队
function FormationManager:reqArenaFormation()
    local parmas = {
        -- 需要五个数据，空位用0补齐
        attack_heroIds = DataManager.FormationData:getArenaAttackFormation(),-- 进攻编队
        defend_heroIds = DataManager.FormationData:getArenaDefendFormation(),-- 防守编队
    }
    self:sendMessage(ProtoMsgType.FromMsgEnum.PVPHeroesArrayReq, parmas, {}, self.rspArenaFormation, nil)
end

function FormationManager:rspArenaFormation(result)
    if result.err_code == GConst.ERROR_STR.SUCCESS then
		if result.reqData then
			DataManager.FormationData:initArena(result.reqData.attack_heroIds, result.reqData.defend_heroIds)
		end
    end
end

return FormationManager