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

/**
 * Seed module tests — verify built-in task definitions are well-formed.
 * We can't test the actual Cosmos upsert here without mocking,
 * so we validate the task shapes via the Zod schema.
 */

import { ExtractionTaskSchema } from './types.js';

// Inline the same task list to verify schema compliance
const BUILTIN_TASK_IDS = [
  'transcript-extraction',
  'triage',
  'memory-insight',
  'reflection-enrichment',
  'bug-report-extraction',
  'timer-parse',
];

describe('seed built-in tasks', () => {
  it('defines exactly 6 built-in tasks', () => {
    expect(BUILTIN_TASK_IDS).toHaveLength(6);
  });

  it('all task IDs are unique', () => {
    const unique = new Set(BUILTIN_TASK_IDS);
    expect(unique.size).toBe(BUILTIN_TASK_IDS.length);
  });

  it('transcript-extraction task validates against schema', () => {
    const result = ExtractionTaskSchema.safeParse({
      id: 'transcript-extraction',
      name: 'Transcript Extraction',
      prompt: 'Extract action items, decisions, questions, deadlines, people, and topics.',
      classes: ['action_item', 'decision', 'question', 'deadline', 'person', 'topic'],
      builtIn: true,
      productId: 'lysnrai',
    });
    expect(result.success).toBe(true);
  });

  it('triage task validates against schema', () => {
    const result = ExtractionTaskSchema.safeParse({
      id: 'triage',
      name: 'MindLyst Triage',
      prompt: 'Analyze captures and extract topics, entities, actions, emotions, brain signals.',
      classes: ['topic', 'entity', 'action', 'emotion', 'date_reference', 'brain_signal'],
      builtIn: true,
      productId: 'lysnrai',
    });
    expect(result.success).toBe(true);
  });

  it('memory-insight task validates against schema', () => {
    const result = ExtractionTaskSchema.safeParse({
      id: 'memory-insight',
      name: 'Memory Insight Extraction',
      prompt: 'Extract patterns, themes, relationships, milestones.',
      classes: ['pattern', 'recurring_theme', 'relationship', 'milestone'],
      builtIn: true,
      productId: 'lysnrai',
    });
    expect(result.success).toBe(true);
  });

  it('reflection-enrichment task validates against schema', () => {
    const result = ExtractionTaskSchema.safeParse({
      id: 'reflection-enrichment',
      name: 'Reflection Enrichment',
      prompt: 'Extract emotional states, accomplishments, concerns, goal progress.',
      classes: ['emotional_state', 'accomplishment', 'concern', 'goal_progress'],
      builtIn: true,
      productId: 'lysnrai',
    });
    expect(result.success).toBe(true);
  });

  it('bug-report-extraction task validates against schema', () => {
    const result = ExtractionTaskSchema.safeParse({
      id: 'bug-report-extraction',
      name: 'Bug Report Extraction',
      prompt: 'Extract STR, expected, actual, component, severity.',
      classes: [
        'steps_to_reproduce',
        'expected_behavior',
        'actual_behavior',
        'affected_component',
        'severity',
      ],
      builtIn: true,
      productId: 'lysnrai',
    });
    expect(result.success).toBe(true);
  });

  it('timer-parse task validates against schema', () => {
    const result = ExtractionTaskSchema.safeParse({
      id: 'timer-parse',
      name: 'Timer Natural Language Parse',
      prompt:
        'Parse timer request and extract time, duration, urgency, label, recurrence, travel context.',
      classes: ['time', 'duration', 'urgency_hint', 'label', 'recurrence', 'travel_context'],
      builtIn: true,
      productId: 'lysnrai',
    });
    expect(result.success).toBe(true);
  });
});
