import { HeatPumpState } from '../models/heatpump';
import {
  FAULT_MESSAGES_1,
  FAULT_MESSAGES_2,
  FAULT_MESSAGES_3,
  FAULT_MESSAGES_4,
} from '../constants';

export const getErrors = (state?: HeatPumpState): Array<string> => {
  const errors: Array<string> = [];
  if (!state) return errors;
  state.faults.error_1?.forEach(error => {
    if (FAULT_MESSAGES_1[error]) errors.push(FAULT_MESSAGES_1[error]);
  });
  state.faults.error_2?.forEach(error => {
    if (FAULT_MESSAGES_2[error]) errors.push(FAULT_MESSAGES_2[error]);
  });
  state.faults.error_3?.forEach(error => {
    if (FAULT_MESSAGES_3[error]) errors.push(FAULT_MESSAGES_3[error]);
  });
  state.faults.error_4?.forEach(error => {
    if (FAULT_MESSAGES_4[error]) errors.push(FAULT_MESSAGES_4[error]);
  });
  return errors;
};
