import { TicketChatListItem } from 'src/types/chats';
import { ERROR_CODE, Topic } from 'src/types/tickets';

export const getMessageErrorCode = (codeError, t) => {
  const checkErrorCode = ERROR_CODE[codeError];
  if (checkErrorCode) return t(`${codeError}`);
  return t('ERROR_CREATING_TICKET');
};

export const isTopicResponsible = (userId: number, topic: Topic): boolean =>
  !!topic?.responsibles?.some(
    responsible => userId === responsible?.responsible?.id,
  );

export const isTicketResponsible = (
  userId: number,
  ticket: TicketChatListItem,
): boolean => ticket?.responsibleId === userId;
