/**
 * Legal Matters Tests
 */

import { describe, it, expect } from 'vitest';
import {
  createLegalMatter,
  getLegalMatter,
  addMatterParticipant,
  linkDocumentToMatter,
  getMatterDocuments,
} from '@the-order/database';

describe('Legal Matters', () => {
  it('should create a legal matter', async () => {
    const matter = await createLegalMatter({
      matter_number: 'MAT-2024-001',
      title: 'Test Matter',
      status: 'open',
    });

    expect(matter).toBeDefined();
    expect(matter.matter_number).toBe('MAT-2024-001');
    expect(matter.status).toBe('open');
  });

  it('should add participant to matter', async () => {
    const matter = await createLegalMatter({
      matter_number: 'MAT-2024-002',
      title: 'Test Matter',
    });

    const participant = await addMatterParticipant(matter.id, {
      user_id: 'test-user-id',
      role: 'lead_counsel',
    });

    expect(participant).toBeDefined();
    expect(participant.role).toBe('lead_counsel');
  });

  it('should link document to matter', async () => {
    const matter = await createLegalMatter({
      matter_number: 'MAT-2024-003',
      title: 'Test Matter',
    });

    const { createDocument } = await import('@the-order/database');
    const document = await createDocument({
      title: 'Test Document',
      type: 'legal',
    });

    const link = await linkDocumentToMatter(matter.id, document.id, 'primary_evidence');

    expect(link).toBeDefined();
    expect(link.matter_id).toBe(matter.id);
    expect(link.document_id).toBe(document.id);
  });
});

