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

export interface AllimEventJson {
  title?: string;
  content?: string;
  sendName?: string;
  postDate?: string;
}

export const decodeAllimEventJson: EventJsonDecoder<AllimEventJson> = (
  message: string
) => {
  try {
    const json = JsonAnalization.receiveAnalization(message);

    return {
      title: json.title,
      content: json.content,
      sendName: json.send_name,
      postDate: json.post_date
    } as AllimEventJson;
  } catch (e) {
    return {} as AllimEventJson;
  }
};
