package dbc

import (
	"github.com/fiskerinc/cloud-services/pkg/dbc/diagnostics"
	fm29_frsd21 "github.com/fiskerinc/cloud-services/pkg/dbc/fm29_frsd21"
	"github.com/fiskerinc/cloud-services/pkg/dbc/models"
	"github.com/fiskerinc/cloud-services/pkg/dbc/state"
)

func NewFM29_FRSD21_DBC() models.DBCVersionInterface {
	fm29_frsd0md := &fm29_frsd21.MessagesDescriptor{}
	fm29_frsd0db := fm29_frsd0md.Database()

	return models.NewDBCVersion(fm29_frsd0db, fm29_frsd21.Hash).
		// bbus.go
		AddMsg(models.NewCANMessage(532, 23).
			Signal(2, state.VCU_RdyLamp, state.FloatToBool).
			Signal(8, state.VCU_GearSig, state.IntFloor)).
		AddMsg(models.NewCANMessage(792, 17).
			Signal(10, state.ESP_VehSpd, state.RoundMilli)).
		AddMsg(models.NewCANMessage(608, 12).
			Signal(4, state.VCU_VehChrgDchgMod, state.GetMappedStrValues(map[float64]string{
				0: "Initial_value",
				1: "DC_charging",
				2: "VTOL_discharging",
				3: "VTOV_discharging",
				4: "AC_charging",
				5: "V2L_trunk_active",
			}))).
		AddMsg(models.NewCANMessage(681, 5).
			Signal(1, state.IBS_BatteryVoltage, state.RoundMilli)).
		AddMsg(models.NewCANMessage(757, 4).
			Signal(0, state.BMS_Bat_SoC_usable, state.IntFloor).
			Signal(2, state.BMS_Bat_SOH, state.IntFloor)).
		AddMsg(models.NewCANMessage(801, 6).
			Signal(0, state.BCM_AP_FL_LeFrntWinPosnInfo, state.IntCeil).
			Signal(1, state.BCM_AP_FL_RiFrntWinPosnInfo, state.IntCeil).
			Signal(2, state.BCM_AP_FL_LeReWinPosnInfo, state.IntCeil).
			Signal(3, state.BCM_AP_FL_RiReWinPosnInfo, state.IntCeil)).
		AddMsg(models.NewCANMessage(816, 14).
			Signal(4, state.BMS_PwrBattRmngCpSOC, state.IntFloor)).
		AddMsg(models.NewCANMessage(821, 37).
			Signal(21, state.BCM_ReDefrstHeatgCmd, state.FloatToBool)).
		AddMsg(models.NewCANMessage(835, 34).
			Signal(4, state.BCM_FrntHoodLidSts, state.FloatToBool).
			Signal(6, state.BCM_FrntDrDoorLockSts, state.FloatToBool).
			Signal(9, state.BCM_DrFrntDoorSts, state.FloatToBool).
			Signal(10, state.BCM_PasFrntDoorSts, state.FloatToBool).
			Signal(12, state.BCM_CenLockSwtSts, state.IntFloor).
			Signal(14, state.BCM_RiReDoorSts, state.FloatToBool).
			Signal(15, state.BCM_LeReDoorSts, state.FloatToBool).
			Signal(29, state.BCM_SunroofPosnInfo, state.IntCeil)).
		AddMsg(models.NewCANMessage(873, 12).
			Signal(0, state.BCM_AP_TL_LeReWinPosnInfo, state.IntCeil).
			Signal(1, state.BCM_AP_TL_RiReWinPosnInfo, state.IntCeil).
			Signal(2, state.BCM_AP_RW_WinPosnInfo, state.IntCeil)).
		AddMsg(models.NewCANMessage(882, 14).
			Signal(6, state.BMS_BattAvrgT, state.IntFloor)).
		AddMsg(models.NewCANMessage(883, 24).
			Signal(15, state.ECC_OutdT, state.IntFloor)).
		AddMsg(models.NewCANMessage(902, 8).
			Signal(0, state.BCM_HeatedSteerWhlSt, state.FloatToBool)).
		AddMsg(models.NewCANMessage(1284, 16).
			Signal(12, state.VCU_DrvgMilg, state.IntFloor)).
		AddMsg(models.NewCANMessage(1298, 5).
			Signal(0, state.PSM_PassSeatHeatgSts, state.IntFloor)).
		AddMsg(models.NewCANMessage(1304, 6).
			Signal(0, state.DSMC_DrvrSeatHeatgSts, state.IntFloor)).
		AddMsg(models.NewCANMessage(1329, 7).
			Signal(1, state.ICC_TotMilg_ODO, state.IntFloor)).
		AddMsg(models.NewCANMessage(1408, 4).
			Signal(2, state.VCU_DCChrgRmngTi, state.Int)).
		AddMsg(models.NewCANMessage(1410, 7).
			Signal(0, state.ECC_InsdT, state.IntFloor).
			Signal(2, state.ECC_RemTSetSts, state.IntFloor)).
		AddMsg(models.NewCANMessage(1137, 21).
			Signal(17, state.PLGM_TrSts, state.FloatToBool)).
		// ibus2.go
		AddMsg(models.NewCANMessage(1317, 3).
			Signal(2, state.TBOX_GPSHei, state.RoundMilli)).
		AddMsg(models.NewCANMessage(1318, 2).
			Signal(0, state.TBOX_GPSLongi, state.RoundGPS).
			Signal(1, state.TBOX_GPSLati, state.RoundGPS)).
		AddMsg(models.NewCANMessage(345, 10).
			Signal(5, state.ACU_Drvr_Occpt_St, state.Int)).
		AddMsg(models.NewCANMessage(819, 12).
			Signal(4, state.BCM_PwrMod, state.Int)).
		AddMsg(models.NewCANMessage(1316, 4).
			Signal(0, state.PWC_ChrgSts, state.Int)).
		// Alexander Andrews Immobilization status possible signals
		AddMsg(models.NewCANMessage(54, 99).
			Signal(15, state.TBOX_RemCtrlCmdFb, state.GetMappedStrValues(map[float64]string{
				0: "Void",
				1: "Successful",
				2: "Failed",
				3: "Reserved",
			}))).
		AddMsg(models.NewCANMessage(537, 23).
			Signal(3, state.VCU_IMMO_Sts, state.GetMappedStrValues(map[float64]string{
				0: "Immo_Active",
				1: "Immo_Inactive",
				2: "Reserved",
				3: "Invalid",
			}))).
		AddMsg(models.NewCANMessage(817, 15).
			Signal(7, state.PKC_IMMO_AuthSts, state.GetMappedStrValues(map[float64]string{
				0: "Initial",
				1: "Auth_Valid",
				2: "Auth_Invalid",
				3: "Invalid",
			}))).
		SetDiagnosticFlags(diagnostics.FM29FRSD0DiagnosticFlags)
}
