import { MAX_AUTO_SAVE_SIZE_BYTES } from '../constants/attachment.constants';
import type { Attachment } from '../models/attachment.model';

export function isAttachmentMedia(attachment: Pick<Attachment, 'mime'>): boolean {
  return attachment.mime.startsWith('image/') ||
    attachment.mime.startsWith('video/') ||
    attachment.mime.startsWith('audio/');
}

export function shouldAutoRequestWhenWatched(attachment: Attachment): boolean {
  return attachment.isImage ||
    (isAttachmentMedia(attachment) && attachment.size <= MAX_AUTO_SAVE_SIZE_BYTES);
}

export function shouldPersistDownloadedAttachment(attachment: Pick<Attachment, 'size' | 'mime'>): boolean {
  return attachment.size <= MAX_AUTO_SAVE_SIZE_BYTES ||
    attachment.mime.startsWith('video/') ||
    attachment.mime.startsWith('audio/');
}
