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;
  }
};
