using System;
using System.Collections.Generic;
using Cute;
using LitJson;
using UnityEngine;
using Wizard;
using Wizard.Lottery;

public class QuestResultReporter : IBattleResultReporter
{
	private readonly GameObject _reportEndAgentObj;

	private readonly QuestReportEndAgent _reportEndAgent;

	public bool IsEnd => _reportEndAgent.IsEnd;

	public int ClassExp => GetClassExp();

	public List<UserAchievement> UserAchievement => GetUserAchievementList();

	public List<UserMission> UserMission => GetUserMissionList();

	public List<ReceivedReward> MissionRewards => GetRewardsList();

	public List<ReceivedReward> VictoryRewards => null;

	public LotteryApplyData LotteryData => Data.QuestFinish.data.AchievedInfo._lotteryData;

	public MyPageHomeDialogData HomeDialogData => null;

	public bool IsDataExist => true;

	public QuestResultReporter()
	{
		_reportEndAgentObj = new GameObject();
		_reportEndAgent = _reportEndAgentObj.AddComponent<QuestReportEndAgent>();
	}

	public void Report(bool isWin)
	{
		StartFinishQuest(isWin, delegate
		{
			_reportEndAgent.Finished();
		});
	}

	public void StartFinishQuest(bool isWin, Action callback)
	{
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		BattleManagerBase ins = BattleManagerBase.GetIns();
		LocalLog.RecordCheckLog(LocalLog.RecordType.CERBERUS, isWin);
		SkillOptionValue skillOptionValue = new SkillOptionValue(SkillCreator.ParseContentInfos("mission_info={me.main_place.class.turn}"));
		SkillCollectionBase.SetupOptionValue(skillOptionValue, ins.GetBattlePlayerPair(isPlayer: true), ins.GetBattlePlayer(isPlayer: true).Class, null);
		BaseTask baseTask = null;
		if (BattleManagerBase.GetIns().IsPuzzleMgr)
		{
			int id = (BattleManagerBase.GetIns() as PuzzleBattleManager).PuzzleQuestData.Id;
			baseTask = new QuestFinishTask(isPuzzle: true);
			(baseTask as QuestFinishTask).SetParameterForPuzzle(id, isWin);
		}
		else if (dataMgr.m_BattleType == DataMgr.BattleType.BossRushQuest)
		{
			baseTask = new BossRushFinishTask();
			(baseTask as BossRushFinishTask).SetParameter(BattleManagerBase.GetIns().BattlePlayer.Class.Life, BattleManagerBase.GetIns().BattlePlayer.Class.MaxLife, dataMgr.BossRushBattleData.QuestStageId, dataMgr.GetSelectDeckId(), isWin, dataMgr.GetSelectDeckFormat(), dataMgr.IsLastSelectDeckAttributeType(DeckAttributeType.BuildDeck), dataMgr.IsLastSelectDeckAttributeType(DeckAttributeType.TrialDeck), ins.IsFirst, skillOptionValue.GetInt(SkillFilterCreator.ContentKeyword.mission_info, 0));
		}
		else if (dataMgr.m_BattleType == DataMgr.BattleType.SecretBossQuest)
		{
			baseTask = new BossRushHiddenBattleFinishTask();
			(baseTask as BossRushHiddenBattleFinishTask).SetParameter(dataMgr.BossRushBattleData.QuestStageId, dataMgr.GetSelectDeckId(), isWin, dataMgr.GetSelectDeckFormat(), dataMgr.IsLastSelectDeckAttributeType(DeckAttributeType.BuildDeck), dataMgr.IsLastSelectDeckAttributeType(DeckAttributeType.TrialDeck), ins.IsFirst, skillOptionValue.GetInt(SkillFilterCreator.ContentKeyword.mission_info, 0));
		}
		else
		{
			baseTask = new QuestFinishTask();
			(baseTask as QuestFinishTask).SetParameter(dataMgr.QuestBattleData.QuestStageId, dataMgr.GetSelectDeckId(), isWin, dataMgr.GetSelectDeckFormat(), dataMgr.IsLastSelectDeckAttributeType(DeckAttributeType.BuildDeck), dataMgr.IsLastSelectDeckAttributeType(DeckAttributeType.TrialDeck), ins.IsFirst, skillOptionValue.GetInt(SkillFilterCreator.ContentKeyword.mission_info, 0));
		}
		_reportEndAgent.StartCoroutine(Toolbox.NetworkManager.Connect(baseTask, delegate
		{
			callback.Call();
		}, BaseTask.OnRequestFailed, BaseTask.OnFailedErrorCode));
	}

	public void Destroy()
	{
		UnityEngine.Object.Destroy(_reportEndAgentObj);
	}

	public JsonData GetFinishResponseData()
	{
		return Data.QuestFinish.data._responseData;
	}

	public List<UserAchievement> GetUserAchievementList()
	{
		return Data.QuestFinish.data.achieved_achievement_list;
	}

	public List<UserMission> GetUserMissionList()
	{
		return Data.QuestFinish.data.achieved_mission_list;
	}

	public List<ReceivedReward> GetRewardsList()
	{
		return Data.QuestFinish.data.Rewards;
	}

	public int GetClassExp()
	{
		return Data.QuestFinish.data.get_class_chara_experience;
	}
}
