import { EventJsonDecoder } from './event-json';
import { JsonAnalization } from '@ucap-webmessenger/api';

export interface TranslationEventJson {
  locale?: string;
  original?: string;
  translation?: string;
  stickername?: string;
  stickerfile?: string;
}

export const decodeTranslationEventJson: EventJsonDecoder<TranslationEventJson> = (
  message: string
) => {
  try {
    const json = JsonAnalization.receiveAnalization(message);
    return {
      locale: json.locale,
      original: json.original,
      translation: json.translation,
      stickername: json.stickername,
      stickerfile: json.stickerfile
    } as TranslationEventJson;
  } catch (e) {
    return {} as TranslationEventJson;
  }
};
