using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class EdlErrorCodeInfo
{
	public static EdlErrorCodeEnum ValueToEdlErrorCode(uint value)
	{
		return value switch
		{
			0u => EdlErrorCodeEnum.EDL_OK, 
			1u => EdlErrorCodeEnum.EDL_errTARGET, 
			2u => EdlErrorCodeEnum.EDL_errFILE, 
			3u => EdlErrorCodeEnum.EDL_errWRITE, 
			4u => EdlErrorCodeEnum.EDL_errERASE, 
			5u => EdlErrorCodeEnum.EDL_errCHECK_ERASED, 
			6u => EdlErrorCodeEnum.EDL_errPROG, 
			7u => EdlErrorCodeEnum.EDL_errVERIFY, 
			8u => EdlErrorCodeEnum.EDL_errADDRESS, 
			9u => EdlErrorCodeEnum.EDL_errNOTDONE, 
			10u => EdlErrorCodeEnum.EDL_errFIRMWARE, 
			11u => EdlErrorCodeEnum.EDL_errVENDOR, 
			12u => EdlErrorCodeEnum.EDL_errUSBR, 
			13u => EdlErrorCodeEnum.EDL_errPOR, 
			14u => EdlErrorCodeEnum.EDL_errUNKNOWN, 
			15u => EdlErrorCodeEnum.EDL_errSTALLEDPKT, 
			16u => EdlErrorCodeEnum.EDL_errINVALID, 
			17u => EdlErrorCodeEnum.EDL_errREAD, 
			18u => EdlErrorCodeEnum.EDL_errFlash, 
			19u => EdlErrorCodeEnum.EDL_errPATCH_CRC, 
			20u => EdlErrorCodeEnum.EDL_errPATCH_ID, 
			21u => EdlErrorCodeEnum.EDL_errPATCH_WRONG_VER, 
			22u => EdlErrorCodeEnum.EDL_errPATCH_SMALL_VER, 
			23u => EdlErrorCodeEnum.EDL_errPATCH_REGION, 
			24u => EdlErrorCodeEnum.EDL_errPATCH_NOPATCH, 
			25u => EdlErrorCodeEnum.EDL_errPATCH_WRONG_ANTIROLBCKVER, 
			32u => EdlErrorCodeEnum.EDL_errPATCH_OTP_WR, 
			33u => EdlErrorCodeEnum.EDL_errPATCH_INVALID_PATCH_PER_OTP, 
			34u => EdlErrorCodeEnum.EDL_errPATCH_INVALID_PATCH_HEADER, 
			35u => EdlErrorCodeEnum.EDL_errPATCH_INVALID_RSA_KEY, 
			36u => EdlErrorCodeEnum.EDL_errPATCH_INVALID_RSA_SIGNATURE, 
			37u => EdlErrorCodeEnum.EDL_errPATCH_INVALID_SERIAL_NO, 
			_ => EdlErrorCodeEnum.InvalidEdlErrorCodeValue, 
		};
	}

	public static uint EdlErrorCodeToValue(EdlErrorCodeEnum enumItem)
	{
		return enumItem switch
		{
			EdlErrorCodeEnum.EDL_OK => 0u, 
			EdlErrorCodeEnum.EDL_errTARGET => 1u, 
			EdlErrorCodeEnum.EDL_errFILE => 2u, 
			EdlErrorCodeEnum.EDL_errWRITE => 3u, 
			EdlErrorCodeEnum.EDL_errERASE => 4u, 
			EdlErrorCodeEnum.EDL_errCHECK_ERASED => 5u, 
			EdlErrorCodeEnum.EDL_errPROG => 6u, 
			EdlErrorCodeEnum.EDL_errVERIFY => 7u, 
			EdlErrorCodeEnum.EDL_errADDRESS => 8u, 
			EdlErrorCodeEnum.EDL_errNOTDONE => 9u, 
			EdlErrorCodeEnum.EDL_errFIRMWARE => 10u, 
			EdlErrorCodeEnum.EDL_errVENDOR => 11u, 
			EdlErrorCodeEnum.EDL_errUSBR => 12u, 
			EdlErrorCodeEnum.EDL_errPOR => 13u, 
			EdlErrorCodeEnum.EDL_errUNKNOWN => 14u, 
			EdlErrorCodeEnum.EDL_errSTALLEDPKT => 15u, 
			EdlErrorCodeEnum.EDL_errINVALID => 16u, 
			EdlErrorCodeEnum.EDL_errREAD => 17u, 
			EdlErrorCodeEnum.EDL_errFlash => 18u, 
			EdlErrorCodeEnum.EDL_errPATCH_CRC => 19u, 
			EdlErrorCodeEnum.EDL_errPATCH_ID => 20u, 
			EdlErrorCodeEnum.EDL_errPATCH_WRONG_VER => 21u, 
			EdlErrorCodeEnum.EDL_errPATCH_SMALL_VER => 22u, 
			EdlErrorCodeEnum.EDL_errPATCH_REGION => 23u, 
			EdlErrorCodeEnum.EDL_errPATCH_NOPATCH => 24u, 
			EdlErrorCodeEnum.EDL_errPATCH_WRONG_ANTIROLBCKVER => 25u, 
			EdlErrorCodeEnum.EDL_errPATCH_OTP_WR => 32u, 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_PATCH_PER_OTP => 33u, 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_PATCH_HEADER => 34u, 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_RSA_KEY => 35u, 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_RSA_SIGNATURE => 36u, 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_SERIAL_NO => 37u, 
			_ => uint.MaxValue, 
		};
	}

	public static string EdlErrorCodeToString(EdlErrorCodeEnum enumItem)
	{
		return enumItem switch
		{
			EdlErrorCodeEnum.EDL_OK => "EDL_OK", 
			EdlErrorCodeEnum.EDL_errTARGET => "EDL_errTARGET", 
			EdlErrorCodeEnum.EDL_errFILE => "EDL_errFILE", 
			EdlErrorCodeEnum.EDL_errWRITE => "EDL_errWRITE", 
			EdlErrorCodeEnum.EDL_errERASE => "EDL_errERASE", 
			EdlErrorCodeEnum.EDL_errCHECK_ERASED => "EDL_errCHECK_ERASED", 
			EdlErrorCodeEnum.EDL_errPROG => "EDL_errPROG", 
			EdlErrorCodeEnum.EDL_errVERIFY => "EDL_errVERIFY", 
			EdlErrorCodeEnum.EDL_errADDRESS => "EDL_errADDRESS", 
			EdlErrorCodeEnum.EDL_errNOTDONE => "EDL_errNOTDONE", 
			EdlErrorCodeEnum.EDL_errFIRMWARE => "EDL_errFIRMWARE", 
			EdlErrorCodeEnum.EDL_errVENDOR => "EDL_errVENDOR", 
			EdlErrorCodeEnum.EDL_errUSBR => "EDL_errUSBR", 
			EdlErrorCodeEnum.EDL_errPOR => "EDL_errPOR", 
			EdlErrorCodeEnum.EDL_errUNKNOWN => "EDL_errUNKNOWN", 
			EdlErrorCodeEnum.EDL_errSTALLEDPKT => "EDL_errSTALLEDPKT", 
			EdlErrorCodeEnum.EDL_errINVALID => "EDL_errINVALID", 
			EdlErrorCodeEnum.EDL_errREAD => "EDL_errREAD", 
			EdlErrorCodeEnum.EDL_errFlash => "EDL_errFlash", 
			EdlErrorCodeEnum.EDL_errPATCH_CRC => "EDL_errPATCH_CRC", 
			EdlErrorCodeEnum.EDL_errPATCH_ID => "EDL_errPATCH_ID", 
			EdlErrorCodeEnum.EDL_errPATCH_WRONG_VER => "EDL_errPATCH_WRONG_VER", 
			EdlErrorCodeEnum.EDL_errPATCH_SMALL_VER => "EDL_errPATCH_SMALL_VER", 
			EdlErrorCodeEnum.EDL_errPATCH_REGION => "EDL_errPATCH_REGION", 
			EdlErrorCodeEnum.EDL_errPATCH_NOPATCH => "EDL_errPATCH_NOPATCH", 
			EdlErrorCodeEnum.EDL_errPATCH_WRONG_ANTIROLBCKVER => "EDL_errPATCH_WRONG_ANTIROLBCKVER", 
			EdlErrorCodeEnum.EDL_errPATCH_OTP_WR => "EDL_errPATCH_OTP_WR", 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_PATCH_PER_OTP => "EDL_errPATCH_INVALID_PATCH_PER_OTP", 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_PATCH_HEADER => "EDL_errPATCH_INVALID_PATCH_HEADER", 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_RSA_KEY => "EDL_errPATCH_INVALID_RSA_KEY", 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_RSA_SIGNATURE => "EDL_errPATCH_INVALID_RSA_SIGNATURE", 
			EdlErrorCodeEnum.EDL_errPATCH_INVALID_SERIAL_NO => "EDL_errPATCH_INVALID_SERIAL_NO", 
			_ => "Invalid EdlErrorCode Value", 
		};
	}

	public static string EdlErrorCodeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = EDL_OK");
		stringBuilder.AppendLine("0x1 = EDL_errTARGET");
		stringBuilder.AppendLine("0x2 = EDL_errFILE");
		stringBuilder.AppendLine("0x3 = EDL_errWRITE");
		stringBuilder.AppendLine("0x4 = EDL_errERASE");
		stringBuilder.AppendLine("0x5 = EDL_errCHECK_ERASED");
		stringBuilder.AppendLine("0x6 = EDL_errPROG");
		stringBuilder.AppendLine("0x7 = EDL_errVERIFY");
		stringBuilder.AppendLine("0x8 = EDL_errADDRESS");
		stringBuilder.AppendLine("0x9 = EDL_errNOTDONE");
		stringBuilder.AppendLine("0xA = EDL_errFIRMWARE");
		stringBuilder.AppendLine("0xB = EDL_errVENDOR");
		stringBuilder.AppendLine("0xC = EDL_errUSBR");
		stringBuilder.AppendLine("0xD = EDL_errPOR");
		stringBuilder.AppendLine("0xE = EDL_errUNKNOWN");
		stringBuilder.AppendLine("0xF = EDL_errSTALLEDPKT");
		stringBuilder.AppendLine("0x10 = EDL_errINVALID");
		stringBuilder.AppendLine("0x11 = EDL_errREAD");
		stringBuilder.AppendLine("0x12 = EDL_errFlash");
		stringBuilder.AppendLine("0x13 = EDL_errPATCH_CRC");
		stringBuilder.AppendLine("0x14 = EDL_errPATCH_ID");
		stringBuilder.AppendLine("0x15 = EDL_errPATCH_WRONG_VER");
		stringBuilder.AppendLine("0x16 = EDL_errPATCH_SMALL_VER");
		stringBuilder.AppendLine("0x17 = EDL_errPATCH_REGION");
		stringBuilder.AppendLine("0x18 = EDL_errPATCH_NOPATCH");
		stringBuilder.AppendLine("0x19 = EDL_errPATCH_WRONG_ANTIROLBCKVER");
		stringBuilder.AppendLine("0x20 = EDL_errPATCH_OTP_WR");
		stringBuilder.AppendLine("0x21 = EDL_errPATCH_INVALID_PATCH_PER_OTP");
		stringBuilder.AppendLine("0x22 = EDL_errPATCH_INVALID_PATCH_HEADER");
		stringBuilder.AppendLine("0x23 = EDL_errPATCH_INVALID_RSA_KEY");
		stringBuilder.AppendLine("0x24 = EDL_errPATCH_INVALID_RSA_SIGNATURE");
		stringBuilder.AppendLine("0x25 = EDL_errPATCH_INVALID_SERIAL_NO");
		return stringBuilder.ToString();
	}
}
