using Wizard.Battle.Phase;
using Wizard.Battle.Recovery;
using Wizard.Battle.Replay;
using Wizard.Battle.Resource;
using Wizard.Battle.View.Vfx;

namespace Wizard.BattleMgr;

public class RecoveryNetworkBattleMgrContentsCreator : IBattleMgrContentsCreator
{
	public int RandomSeed => Data.BattleRecoveryInfo.seed;

	public IRecoveryManager RecoveryManager { get; protected set; }

	public IRecoveryRecordManager RecoveryRecordManager { get; private set; }

	public IReplayRecordManager ReplayRecordManager { get; private set; }

	public RecoveryController RecoveryControllerInstance { get; private set; }

	public RecoveryNetworkBattleMgrContentsCreator()
	{
		RecoveryManager = new NetworkBattleRecoveryManager();
		RecoveryRecordManager = new NullRecoveryRecordManager();
		ReplayRecordManager = new ReplayRecordManager();
		RecoveryControllerInstance = new RecoveryController(GameMgr.GetIns().IsAINetwork ? new RecoveryOperationInfo(OperationRecorderBase.RecordDirectoryPath + "recovery_ai_network.json") : null);
		RecoveryControllerInstance.OnFinishRecoveryLogSync += delegate
		{
			if (GameMgr.GetIns().IsAINetwork)
			{
				RecoveryRecordManager = new AINetworkBattleRecoveryRecordManager("recovery_ai_network.json");
				BattleManagerBase.GetIns().StartRecoveryRecording();
			}
			else
			{
				RecoveryRecordManager = new NetworkBattleRecoveryRecordManager();
				ToolboxGame.RealTimeNetworkAgent.StartRecoveryRecording();
			}
		};
	}

	public IBattleResourceMgr CreateResourceMgr()
	{
		if (RecoveryControllerInstance.IsMariganFinished || (GameMgr.GetIns().IsAINetwork && RecoveryControllerInstance.AIBattleRecoveryData.SetupInfo.HasMulliganInfo))
		{
			RecoveryBattleResourceMgr recoveryBattleResourceMgr = new RecoveryBattleResourceMgr();
			RecoveryControllerInstance.OnFinishRecoveringData += recoveryBattleResourceMgr.EnableLoadResouce;
			return recoveryBattleResourceMgr;
		}
		return new BattleResourceMgr();
	}

	public VfxMgr CreateVfxMgr()
	{
		return new VfxMgr();
	}

	public IPhaseCreator CreatePhaseCreator(BattleManagerBase battleMgr)
	{
		battleMgr.IsRecovery = true;
		NetworkBattleManagerBase battleMgr2 = (NetworkBattleManagerBase)battleMgr;
		if (RecoveryControllerInstance.IsMariganFinished || (GameMgr.GetIns().IsAINetwork && RecoveryControllerInstance.AIBattleRecoveryData.SetupInfo.HasMulliganInfo))
		{
			return new RecoveryNetworkBattleMainPhaseCreator(battleMgr2);
		}
		return new RecoveryNetworkBattleMulliganPhaseCreator(battleMgr2);
	}
}
