import { IGenericTextObject } from '../../../../generic/types';
import { ISlackTextObject } from '../../../types';
import { parseSlackMrkdwnToMarkdown } from '../../../parsers/parse-slack-mrkdwn-to-markdown';

export const transformTextObject = ({
  type, text, emoji, verbatim
}: ISlackTextObject): IGenericTextObject => {
  const res: IGenericTextObject = {
      value: type === 'mrkdwn'
        ? parseSlackMrkdwnToMarkdown(text)
        : text,
      type:  type === 'mrkdwn' ? 'markdown' : 'plain',
      slack: {
        type
      }
  };

  if (typeof emoji === 'boolean') {
    res.slack.emoji = emoji;
  }

  if (typeof verbatim === 'boolean') {
    res.slack.verbatim = verbatim;
  }

  return res;
};