import { describe, expect, it } from 'vitest';

import {
  createEmptyProject,
  createMediaAssetReference,
} from '../../../src/project/project.schema';
import { CREATED_AT } from './project-fixture';

describe('project factories', () => {
  it('creates a complete, deterministic empty document when inputs are supplied', () => {
    expect(
      createEmptyProject({
        id: 'project-1',
        name: '  Test  ',
        timestamp: CREATED_AT,
      })
    ).toMatchObject({
      schemaVersion: 1,
      id: 'project-1',
      name: 'Test',
      createdAt: CREATED_AT,
      updatedAt: CREATED_AT,
      assets: [],
      timeline: [],
      output: {
        presetId: 'mp4-h264-balanced',
        fileName: 'output.mp4',
        container: 'mp4',
        sampleRate: 48_000,
        channelLayout: 'stereo',
        missingAudioPolicy: 'insert-silence',
      },
    });
  });

  it('converts File-compatible identity metadata without retaining the File', () => {
    const file = {
      name: 'clip.mov',
      size: 42,
      lastModified: 123,
      type: 'video/quicktime',
    };
    const asset = createMediaAssetReference(file, { id: 'asset-1' });
    expect(asset).toEqual({
      id: 'asset-1',
      originalName: 'clip.mov',
      size: 42,
      lastModified: 123,
      mimeType: 'video/quicktime',
      sourceStatus: 'attached',
    });
    expect(asset).not.toHaveProperty('file');
  });

  it('rejects malformed file identity metadata', () => {
    expect(() =>
      createMediaAssetReference({
        name: '',
        size: -1,
        lastModified: 0,
        type: '',
      })
    ).toThrow();
  });
});
