using System.Collections.Generic;
using QC.QMSLPhone;
using Qualcomm_ModemRFA;

namespace QFDT_Components;

public class availablePaths
{
	public List<availablePathType> availPaths;

	private bool CheckPathIsExist(availablePathType newpath)
	{
		bool result = false;
		for (int i = 0; i < availPaths.Count; i++)
		{
			if (availPaths[i].PRxPath.Ant_Path != newpath.PRxPath.Ant_Path || availPaths[i].PRxPath.Sig_Path != newpath.PRxPath.Sig_Path || availPaths[i].PRxPath.RFM_Device != newpath.PRxPath.RFM_Device || availPaths[i].TxPath.Ant_Path != newpath.TxPath.Ant_Path || availPaths[i].TxPath.Sig_Path != newpath.TxPath.Sig_Path || availPaths[i].TxPath.RFM_Device != newpath.TxPath.RFM_Device)
			{
				continue;
			}
			if (newpath.currentPathType == 2)
			{
				result = true;
				break;
			}
			if (availPaths[i].currentPathType == 2)
			{
				if (newpath.bValidDRx)
				{
					availPaths[i].DRxPath.Ant_Path = newpath.DRxPath.Ant_Path;
					availPaths[i].DRxPath.Sig_Path = newpath.DRxPath.Sig_Path;
					availPaths[i].DRxPath.RFM_Device = newpath.DRxPath.RFM_Device;
					availPaths[i].bValidDRx = true;
				}
				result = true;
				break;
			}
			if (!availPaths[i].bValidDRx && !newpath.bValidDRx)
			{
				result = true;
				break;
			}
			if (availPaths[i].bValidDRx && newpath.bValidDRx && availPaths[i].DRxPath.Ant_Path == newpath.DRxPath.Ant_Path && availPaths[i].DRxPath.Sig_Path == newpath.DRxPath.Sig_Path && availPaths[i].DRxPath.RFM_Device == newpath.DRxPath.RFM_Device)
			{
				result = true;
				break;
			}
		}
		return result;
	}

	public void AddAvailPath(availablePathType path)
	{
		if (path.calAction == 1 || RFPathAndRadioConfiguration.m_platform == Platform.HE)
		{
			if (availPaths == null)
			{
				availPaths = new List<availablePathType>();
			}
			if (availPaths.Count == 0 || RFPathAndRadioConfiguration.m_platform == Platform.HE)
			{
				availPaths.Add(path);
			}
			else if (!CheckPathIsExist(path))
			{
				availPaths.Add(path);
			}
		}
	}

	public void GetAvailablePathViaPhoneRsp(Phone.structRFPathInformationResponse_NoExpanded rsp)
	{
		availPaths = new List<availablePathType>();
		ushort numberofPackets = rsp.responsePayload.numberofPackets;
		if (numberofPackets <= 0 || rsp.responsePayload.packet == null)
		{
			return;
		}
		for (int i = 0; i < rsp.responsePayload.packet.Length; i++)
		{
			if (rsp.responsePayload.packet[i].version1.txrxcalaction == 1)
			{
				availablePathType availablePathType2 = new availablePathType();
				availablePathType2.UpdateAvailPathViaPacket(rsp.responsePayload.packet[i].version1);
				AddAvailPath(availablePathType2);
			}
		}
	}

	public void GetAvailablePathViaPhoneRsp(Phone.structFtmUnifiedTxRxPathInfoResponse rsp)
	{
		availPaths = new List<availablePathType>();
		if (rsp.bandData != null)
		{
			int num_of_paths = rsp.bandData[0].num_of_paths;
			for (int i = 0; i < num_of_paths; i++)
			{
				availablePathType availablePathType2 = new availablePathType();
				availablePathType2.UpdateAvailPathViaPacket(rsp, i);
				AddAvailPath(availablePathType2);
			}
		}
	}
}
