#ifndef _DTC_H_
#define _DTC_H_

#include <Arduino.h>

#define MAX_DTC_STORAGE 12

typedef enum DTCNums_e
{
  DTC_NO_EEPROM_FOUND = 1,
  DTC_EEPROM_CFG_BAD,
  DTC_EEPROM_PDS_BAD,
  DTC_EEPROM_PDSADRESS_BAD,
  DTC_EEPROM_VERSION_BAD,
  DTC_FLASHFS_ERROR,
  DTC_FLASHFS_VERSION_ERROR,
  DTC_EEPROM_CFG_SANITY,
  DTC_NO_LORA_FOUND,
  DTC_NO_BATMNON_FOUND,
  DTC_BAT_LOW,
  DTC_BAT_CRITICAL,
  DTC_LAST_DTC
} DTCNums_t;

typedef enum DTCActive_e
{
  DTC_NONE,
  DTC_ACTIVE,
  DTC_PREVIOUS
} DTCActive_t;

typedef enum DTCSeverity_e
{
  DTC_INFO,
  DTC_WARN,
  DTC_CRITICAL
} DTCSeverity_t;

typedef struct DTCEntry_s
{
  DTCNums_t Number;
  uint32_t timestamp;
  DTCActive_t active;
  DTCSeverity_t severity;
  uint32_t debugVal;
} DTCEntry_t;

void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, uint32_t DebugValue = 0);
void ClearDTC(DTCNums_t DTC_no);
void ClearAllDTC();
DTCNums_t getlastDTC(boolean only_active);
DTCNums_t getlastDTC_Severity(boolean only_active, DTCSeverity_t severity);
void DTC_Process();

extern DTCEntry_s DTCStorage[MAX_DTC_STORAGE];
#endif