/**
 * Extract title from filename by removing extension.
 * Handles multiple dots in filename (e.g., "video.v2.mp4" -> "video.v2")
 */
export function generateTitleFromFilename(filename: string): string {
  const lastDotIndex = filename.lastIndexOf('.');
  if (lastDotIndex > 0) {
    return filename.substring(0, lastDotIndex);
  }
  return filename;
}

/**
 * Generate unique ID for file tracking (not MongoDB ID)
 */
export function generateFileId(): string {
  return crypto.randomUUID();
}

/**
 * Format file size for display
 */
export function formatFileSize(bytes: number): string {
  if (bytes < 1024) {
    return `${bytes} B`;
  }
  if (bytes < 1024 * 1024) {
    return `${Math.round(bytes / 1024)} KB`;
  }
  return `${Math.round(bytes / (1024 * 1024))} MB`;
}
