using System;
using System.Windows;
using QC.QMSLPhone;

namespace QFDT_Components;

public class availablePathType
{
	public RFPathStruct PRxPath;

	public RFPathStruct DRxPath;

	public RFPathStruct TxPath;

	public byte calAction;

	public byte currentPathType;

	public bool bValidDRx;

	public static bool isAT = true;

	public int txPathId;

	public override string ToString()
	{
		string text = (isAT ? $"PRx({PRxPath.RFM_Device},{PRxPath.Sig_Path},{PRxPath.Ant_Path})" : $"PRx({PRxPath.RFM_Device},{PRxPath.Sig_Path},{PRxPath.Ant_Path},{PRxPath.PLL_ID})");
		string text2 = (isAT ? $", Tx({TxPath.RFM_Device},{TxPath.Sig_Path},{TxPath.Ant_Path})" : $", Tx({TxPath.RFM_Device},{TxPath.Sig_Path},{TxPath.Ant_Path},{TxPath.PLL_ID})");
		string text3 = "";
		text3 = ((!isAT) ? $", DRx({DRxPath.RFM_Device},{DRxPath.Sig_Path},{DRxPath.Ant_Path},{DRxPath.PLL_ID})" : (bValidDRx ? $", DRx({DRxPath.RFM_Device},{DRxPath.Sig_Path},{DRxPath.Ant_Path})" : ""));
		return text + text3 + text2;
	}

	private void updateStatusOfValidDRx()
	{
		if (currentPathType == 2 || DRxPath.RFM_Device > 16 || DRxPath.Sig_Path > 16 || DRxPath.Ant_Path > 16)
		{
			bValidDRx = false;
		}
		else
		{
			bValidDRx = true;
		}
	}

	public void UpdateAvailPathViaPacket(Phone.structRFPathInformationPacketVersion1_UtilizeReservedField ver1_packet)
	{
		calAction = ver1_packet.txrxcalaction;
		currentPathType = ver1_packet.rfmPathType;
		if (currentPathType == 0)
		{
			PRxPath.RFM_Device = ver1_packet.rfmDevice;
			PRxPath.Sig_Path = ver1_packet.signalPath;
			PRxPath.Ant_Path = ver1_packet.antennaPath;
			DRxPath.RFM_Device = ver1_packet.associatedRxRFMDevice;
			DRxPath.Sig_Path = ver1_packet.associatedRxSignalPath;
			DRxPath.Ant_Path = ver1_packet.associatedRxAntennaPath;
			TxPath.RFM_Device = ver1_packet.associatedTxRFMDevice;
			TxPath.Sig_Path = ver1_packet.associatedTxSignalPath;
			TxPath.Ant_Path = ver1_packet.associatedTxAntennaPath;
		}
		else if (currentPathType == 1)
		{
			DRxPath.RFM_Device = ver1_packet.rfmDevice;
			DRxPath.Sig_Path = ver1_packet.signalPath;
			DRxPath.Ant_Path = ver1_packet.antennaPath;
			PRxPath.RFM_Device = ver1_packet.associatedRxRFMDevice;
			PRxPath.Sig_Path = ver1_packet.associatedRxSignalPath;
			PRxPath.Ant_Path = ver1_packet.associatedRxAntennaPath;
			TxPath.RFM_Device = ver1_packet.associatedTxRFMDevice;
			TxPath.Sig_Path = ver1_packet.associatedTxSignalPath;
			TxPath.Ant_Path = ver1_packet.associatedTxAntennaPath;
		}
		else if (currentPathType == 2)
		{
			TxPath.RFM_Device = ver1_packet.rfmDevice;
			TxPath.Sig_Path = ver1_packet.signalPath;
			TxPath.Ant_Path = ver1_packet.antennaPath;
			PRxPath.RFM_Device = ver1_packet.associatedRxRFMDevice;
			PRxPath.Sig_Path = ver1_packet.associatedRxSignalPath;
			PRxPath.Ant_Path = ver1_packet.associatedRxAntennaPath;
		}
		updateStatusOfValidDRx();
	}

	public void UpdateAvailPathViaPacket(Phone.structFtmUnifiedTxRxPathInfoResponse rsp, int pathId)
	{
		try
		{
			Phone.structFtmUnifiedTxRxPathInfoVersion0 structFtmUnifiedTxRxPathInfoVersion = rsp.bandData[0].version0Data[pathId];
			calAction = structFtmUnifiedTxRxPathInfoVersion.tx_rx_calaction;
			currentPathType = structFtmUnifiedTxRxPathInfoVersion.path_type;
			int num = 0;
			int num2 = 0;
			if (structFtmUnifiedTxRxPathInfoVersion.associatedRxpaths.Length > 0)
			{
				bValidDRx = true;
				num = structFtmUnifiedTxRxPathInfoVersion.associatedRxpaths[0];
				num2 = structFtmUnifiedTxRxPathInfoVersion.associatedRxpaths[1];
			}
			else
			{
				bValidDRx = false;
			}
			if (currentPathType == 1)
			{
				TxPath.RFM_Device = structFtmUnifiedTxRxPathInfoVersion.rfmpath.rfmDevice;
				TxPath.Sig_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.sigPath;
				TxPath.Ant_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.antennaSwitchPath;
				TxPath.PLL_ID = structFtmUnifiedTxRxPathInfoVersion.rfmpath.pllId;
				PRxPath.RFM_Device = rsp.bandData[0].version0Data[num].rfmpath.rfmDevice;
				PRxPath.Sig_Path = rsp.bandData[0].version0Data[num].rfmpath.sigPath;
				PRxPath.Ant_Path = rsp.bandData[0].version0Data[num].rfmpath.antennaSwitchPath;
				PRxPath.PLL_ID = rsp.bandData[0].version0Data[num].rfmpath.pllId;
				DRxPath.RFM_Device = rsp.bandData[0].version0Data[num2].rfmpath.rfmDevice;
				DRxPath.Sig_Path = rsp.bandData[0].version0Data[num2].rfmpath.sigPath;
				DRxPath.Ant_Path = rsp.bandData[0].version0Data[num2].rfmpath.antennaSwitchPath;
				DRxPath.PLL_ID = rsp.bandData[0].version0Data[num2].rfmpath.pllId;
				txPathId = pathId;
				return;
			}
			int num3 = -1;
			if (structFtmUnifiedTxRxPathInfoVersion.associatedTxpaths.Length > 0)
			{
				num3 = structFtmUnifiedTxRxPathInfoVersion.associatedTxpaths[0];
			}
			if (!bValidDRx)
			{
				PRxPath.RFM_Device = structFtmUnifiedTxRxPathInfoVersion.rfmpath.rfmDevice;
				PRxPath.Sig_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.sigPath;
				PRxPath.Ant_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.antennaSwitchPath;
				PRxPath.PLL_ID = structFtmUnifiedTxRxPathInfoVersion.rfmpath.pllId;
				if (num3 != -1)
				{
					TxPath.RFM_Device = rsp.bandData[0].version0Data[num3].rfmpath.rfmDevice;
					TxPath.Sig_Path = rsp.bandData[0].version0Data[num3].rfmpath.sigPath;
					TxPath.Ant_Path = rsp.bandData[0].version0Data[num3].rfmpath.antennaSwitchPath;
					TxPath.PLL_ID = rsp.bandData[0].version0Data[num3].rfmpath.pllId;
				}
			}
			else if (num == pathId)
			{
				PRxPath.RFM_Device = structFtmUnifiedTxRxPathInfoVersion.rfmpath.rfmDevice;
				PRxPath.Sig_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.sigPath;
				PRxPath.Ant_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.antennaSwitchPath;
				PRxPath.PLL_ID = structFtmUnifiedTxRxPathInfoVersion.rfmpath.pllId;
				DRxPath.RFM_Device = rsp.bandData[0].version0Data[num2].rfmpath.rfmDevice;
				DRxPath.Sig_Path = rsp.bandData[0].version0Data[num2].rfmpath.sigPath;
				DRxPath.Ant_Path = rsp.bandData[0].version0Data[num2].rfmpath.antennaSwitchPath;
				DRxPath.PLL_ID = rsp.bandData[0].version0Data[num2].rfmpath.pllId;
				if (num3 != -1)
				{
					TxPath.RFM_Device = rsp.bandData[0].version0Data[num3].rfmpath.rfmDevice;
					TxPath.Sig_Path = rsp.bandData[0].version0Data[num3].rfmpath.sigPath;
					TxPath.Ant_Path = rsp.bandData[0].version0Data[num3].rfmpath.antennaSwitchPath;
					TxPath.PLL_ID = rsp.bandData[0].version0Data[num3].rfmpath.pllId;
				}
			}
			else
			{
				DRxPath.RFM_Device = structFtmUnifiedTxRxPathInfoVersion.rfmpath.rfmDevice;
				DRxPath.Sig_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.sigPath;
				DRxPath.Ant_Path = structFtmUnifiedTxRxPathInfoVersion.rfmpath.antennaSwitchPath;
				DRxPath.PLL_ID = structFtmUnifiedTxRxPathInfoVersion.rfmpath.pllId;
				PRxPath.RFM_Device = rsp.bandData[0].version0Data[num].rfmpath.rfmDevice;
				PRxPath.Sig_Path = rsp.bandData[0].version0Data[num].rfmpath.sigPath;
				PRxPath.Ant_Path = rsp.bandData[0].version0Data[num].rfmpath.antennaSwitchPath;
				PRxPath.PLL_ID = rsp.bandData[0].version0Data[num].rfmpath.pllId;
				if (num3 != -1)
				{
					TxPath.RFM_Device = rsp.bandData[0].version0Data[num3].rfmpath.rfmDevice;
					TxPath.Sig_Path = rsp.bandData[0].version0Data[num3].rfmpath.sigPath;
					TxPath.Ant_Path = rsp.bandData[0].version0Data[num3].rfmpath.antennaSwitchPath;
					TxPath.PLL_ID = rsp.bandData[0].version0Data[num3].rfmpath.pllId;
				}
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}
}
