using System;
using System.Collections.Generic;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI;

public class FMHCIReceivePacketHandler : ReceivePacketHandlerBase
{
	private List<PacketType> dataTypeList = new List<PacketType>();

	private List<PacketType> eventTypeList = new List<PacketType>();

	private List<PacketType> commandTypeList = new List<PacketType>();

	public FMHCIReceivePacketHandler(PacketListBase packetList)
		: base(packetList)
	{
		dataTypeList.Add(PacketType.Data);
		eventTypeList.Add(PacketType.Notification);
		eventTypeList.Add(PacketType.Response);
		commandTypeList.Add(PacketType.Command);
	}

	protected override PacketBase ConvertBytesToPacket(PacketData packetData)
	{
		if (packetData is FMHCIIncomingPacketData)
		{
			if (((FMHCIIncomingPacketData)packetData).fmhciPacketType == FMHCIPacketDataType.Event)
			{
				return packetList.BytesToPacketOfType(packetData.bytes, eventTypeList);
			}
			if (((FMHCIIncomingPacketData)packetData).fmhciPacketType == FMHCIPacketDataType.Command)
			{
				return packetList.BytesToPacketOfType(packetData.bytes, commandTypeList);
			}
			throw new Exception("Unsupported FM HCI packet type: " + ((FMHCIOutgoingPacketData)packetData).fmhciPacketType);
		}
		return packetList.BytesToPacket(packetData.bytes);
	}
}
