import { NAPError } from './external-interfaces';

interface Error {
  id: number;
  message: string;
  isFatal: boolean;
}

const createFatalError = (id: number, message: string): Error => ({
  id,
  message,
  isFatal: true,
});

const createError = (id: number, message: string): Error => ({
  id,
  message,
  isFatal: false,
});

const innerErrors: { [key: string]: NAPError } = {
  NO_HOSTBRIDGE_100: createFatalError(100, 'No hostbridge found'),
  MALFORMED_HOSTBRIDGE_SET_CALLBACK_105: createFatalError(
    105,
    'Hostbridge is malformed. It is missing a setCallback function'
  ),
  MALFORMED_HOSTBRIDGE_SEND_106: createFatalError(
    106,
    'Hostbridge is malformed. It is missing a send function'
  ),
  MALFORMED_HOSTBRIDGE_SEND_EVEN_THOUGH_MISSING_107: createError(
    107,
    'Hostbridge is malformed. Posting messages to the send function even though it is missing a send function.'
  ),
  MALFORMED_MESSAGE_RECEIVED_NOT_JSON_200: createError(
    200,
    'A message that was not a JSON message was received from the host'
  ),
  MALFORMED_MESSAGE_RECEIVED_MISSING_TYPE_201: createError(
    201,
    'A message missing a type was received from the host'
  ),
  MALFORMED_MESSAGE_RECEIVED_MISSING_TYPE_202: createError(
    202,
    'A message missing a payload was received from the host'
  ),
  WRONG_DATE_FORMAT_400: createError(
    400,
    'Wrong format for date'
  ),
  WRONG_ID_FORMAT_400: createError(
    400,
    'Wrong format for id'
  ),
};

export const Errors = innerErrors;
