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

public class StoryResultReporter : IBattleResultReporter
{
	private readonly GameObject m_reportEndAgentObj;

	private readonly StoryReportEndAgent m_reportEndAgent;

	public bool IsEnd => m_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.StoryFinish.data.AchievedInfo._lotteryData;

	public MyPageHomeDialogData HomeDialogData => null;

	public bool IsDataExist => true;

	public StoryResultReporter()
	{
		m_reportEndAgentObj = new GameObject();
		m_reportEndAgent = m_reportEndAgentObj.AddComponent<StoryReportEndAgent>();
	}

	public void Report(bool isWin)
	{
		StartFinishStory(delegate
		{
			m_reportEndAgent.Finished();
		});
	}

	public void StartFinishStory(Action callback)
	{
		SelectedStoryInfo selectedStoryInfo = Data.SelectedStoryInfo;
		NetworkManager networkManager = Toolbox.NetworkManager;
		BattleManagerBase battleMgr = BattleManagerBase.GetIns();
		if (Convert.ToBoolean(battleMgr.isStorySuccessful))
		{
			selectedStoryInfo.SetPart(ScenarioPart.SecondHalf);
		}
		int cumulativeEvolutionCount = battleMgr.BattlePlayer._cumulativeEvolutionCount;
		int turn = battleMgr.BattlePlayer.Turn;
		LocalLog.RecordCheckLog(LocalLog.RecordType.CERBERUS, battleMgr.isStorySuccessful == 1);
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		StoryFinishTask storyFinishTask = new StoryFinishTask(selectedStoryInfo);
		storyFinishTask.SetParameter(battleMgr.isStorySuccessful, cumulativeEvolutionCount, turn, dataMgr.IsSelectEmptyDeck() ? (dataMgr.GetPlayerClassId() + 90) : dataMgr.GetSelectDeckId(), dataMgr.IsLastSelectDeckAttributeType(DeckAttributeType.BuildDeck), dataMgr.GetSelectDeckFormat(), dataMgr.GetPlayerClassId());
		selectedStoryInfo.IsFailure = battleMgr.isStorySuccessful == 0;
		m_reportEndAgent.StartCoroutine(networkManager.Connect(storyFinishTask, delegate
		{
			if (battleMgr.isStorySuccessful != 0)
			{
				StoryNextSceneSelector.SetDeckRentalLoseCount(0);
			}
			else
			{
				StoryNextSceneSelector.SetDeckRentalLoseCount(StoryNextSceneSelector.GetDeckRentalLoseCount() + 1);
			}
			callback.Call();
		}, BaseTask.OnRequestFailed, BaseTask.OnFailedErrorCode));
	}

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

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

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

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

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

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