import { describe, it, expect } from 'vitest';
import {
  checkMinioExtractorStatus,
  getMinioExtractorInstallHints,
  renderMinioExtractorSetupLines,
  summarizeMinioExtractorStatus,
} from './minioExtractors.js';

describe('minio extractor requirements', () => {
  it('skips checks when backup.minio is not enabled', async () => {
    const status = await checkMinioExtractorStatus({});

    expect(status.minioEnabled).toBe(false);
    expect(status.missingRequirements).toEqual([]);
    expect(renderMinioExtractorSetupLines(status)).toEqual([]);
  });

  it('reports missing pdf/docx extractors', async () => {
    const status = await checkMinioExtractorStatus(
      { backup: { minio: { enabled: true } } },
      async () => false,
    );

    expect(status.minioEnabled).toBe(true);
    expect(status.pdfSupported).toBe(false);
    expect(status.docxSupported).toBe(false);
    expect(status.missingRequirements).toEqual(['pdftotext', 'pandoc or docx2txt']);
    expect(summarizeMinioExtractorStatus(status)).toBe('pdf:missing(pdftotext), docx:missing(pandoc|docx2txt)');
  });

  it('accepts pandoc as docx extractor', async () => {
    const status = await checkMinioExtractorStatus(
      { backup: { minio: { enabled: true } } },
      async (command) => command === 'pdftotext' || command === 'pandoc',
    );

    expect(status.pdfSupported).toBe(true);
    expect(status.docxSupported).toBe(true);
    expect(status.availableDocxExtractors).toEqual(['pandoc']);
    expect(status.missingRequirements).toEqual([]);
  });

  it('returns Homebrew install hint on macOS when extractors are missing', async () => {
    const status = await checkMinioExtractorStatus(
      { backup: { minio: { enabled: true } } },
      async () => false,
    );
    const hints = await getMinioExtractorInstallHints(status, { platform: 'darwin' });
    expect(hints).toEqual(['brew install poppler pandoc']);
  });

  it('returns apt-get install hint on Linux when apt-get is available', async () => {
    const status = await checkMinioExtractorStatus(
      { backup: { minio: { enabled: true } } },
      async () => false,
    );
    const hints = await getMinioExtractorInstallHints(status, {
      platform: 'linux',
      exists: async (command) => command === 'apt-get',
    });
    expect(hints).toEqual(['sudo apt-get install -y poppler-utils pandoc']);
  });
});
