import { FileTypes } from 'src/types/attachments';
import { hasAnyPermissions, UserPermissions } from 'src/utils/permissions';

export const canDelete = (
  loggedUserId: number,
  postUserId: number,
  permissions: string[],
): boolean =>
  hasAnyPermissions(permissions, [UserPermissions.MANAGE_MARKETPLACE_POSTS]) ||
  loggedUserId === postUserId;

export const canEdit = (loggedUserId: number, postUserId: number): boolean =>
  loggedUserId === postUserId;

export const canComment = (permissions: string[]): boolean =>
  hasAnyPermissions(permissions, [
    UserPermissions.CREATE_COMMENT_IN_MARKETPLACE,
    UserPermissions.CREATE_COMMENT,
  ]);

export const canReactContent = (permissions: string[]): boolean =>
  hasAnyPermissions(permissions, [
    UserPermissions.CAN_REACT_MARKETPLACE_POSTS,
    UserPermissions.CAN_REACT_CONTENT,
  ]);

export const canContact = (
  loggedUserId: number,
  postUserId: number,
  permissions: string[],
): boolean =>
  hasAnyPermissions(permissions, [
    UserPermissions.VIEW_REGULAR_CHATS,
    UserPermissions.VIEW_CHATS_V2,
  ]) && loggedUserId !== postUserId;

export const getAttachmentValue = (type: string) => {
  switch (type) {
    case FileTypes.IMAGE:
      return 'images' as const;
      break;
    case FileTypes.VIDEO:
      return 'videos' as const;
      break;
    default:
      return 'files' as const;
  }
};
