using System;
using QCRPG.Framework;
using QCRPG.TSL.NFC.Packets;

namespace QCRPG.TSL.NFC;

public class NFCBuilder : BuilderBase
{
	private NFCMainWorkerThreadInternal nfcMainWorkerThreadInternal;

	private NFCConfigSettings nfcConfigSettings = new NFCConfigSettings();

	private PacketListBase packetListForGooier = new NFCPacketList();

	public override void BuildTSL(PacketReceiveMode packetReceiveMode, bool deviceEmulationMode = false, int dutNumber = 1, bool commandLineMode = false, bool automationMode = false)
	{
		if (deviceEmulationMode)
		{
			throw new Exception("Device emulation mode not supported");
		}
		name = "NFC";
		dutName = "DUT" + dutNumber;
		logger = new Logger(name, dutName);
		if (commandLineMode)
		{
			packetList = new NFCPacketList();
			api = new NFCAPI(packetList, logger, packetReceiveMode);
			nfcMainWorkerThreadInternal = new NFCMainWorkerThreadInternal(logger, (NFCAPI)api);
			workerThreads.Add(nfcMainWorkerThreadInternal);
		}
		else
		{
			configurer = new Configurer();
			packetList = new NFCPacketList();
			api = new NFCAPI(packetList, logger, packetReceiveMode);
			nfcMainWorkerThreadInternal = new NFCMainWorkerThreadInternal(logger, (NFCAPI)api);
			gooier = new NFCGooierInternal(name, logger, configurer, (NFCAPI)api, packetListForGooier, nfcConfigSettings, nfcMainWorkerThreadInternal);
			scripter = new NFCScripterInternal((NFCAPI)api, (NFCPacketList)packetList, logger, nfcConfigSettings);
			workerThreads.Add(nfcMainWorkerThreadInternal);
		}
	}

	public override void SetCombinedScripter(CombinedScripter combinedScripter)
	{
		((NFCGooier)gooier).SetCombinedScripter(combinedScripter);
	}

	public override void ApplicationReady()
	{
		((NFCGooier)gooier).ApplicationReady();
	}
}
