import { describe, it, expect } from 'vitest';
import { validateMhdCompanions } from './mhdCompanions';
import type { StagedFile } from '../types';

function sf(relativePath: string): StagedFile {
  return { name: relativePath.slice(relativePath.lastIndexOf('/') + 1), relativePath, size: 1 };
}

describe('validateMhdCompanions (D6)', () => {
  it('passes when the .mhd has a .raw companion in the same folder', () => {
    expect(validateMhdCompanions([sf('vol.mhd'), sf('vol.raw')])).toEqual([]);
  });
  it('passes with .img and .zraw companions too', () => {
    expect(validateMhdCompanions([sf('a/x.mhd'), sf('a/x.img')])).toEqual([]);
    expect(validateMhdCompanions([sf('a/y.mhd'), sf('a/y.zraw')])).toEqual([]);
  });
  it('fails when the .mhd has no companion', () => {
    const errs = validateMhdCompanions([sf('vol.mhd')]);
    expect(errs).toHaveLength(1);
    expect(errs[0].code).toBe('MHD_COMPANION_MISSING');
    expect(errs[0].file).toBe('vol.mhd');
  });
  it('fails when the companion is in a different folder', () => {
    const errs = validateMhdCompanions([sf('a/vol.mhd'), sf('b/vol.raw')]);
    expect(errs).toHaveLength(1);
  });
  it('passes when there are no .mhd files at all', () => {
    expect(validateMhdCompanions([sf('brain.nii.gz')])).toEqual([]);
  });
});
