import type { JobDefinition } from './job-definition.types';

/**
 * M-AI-06-03: ReviewCard Generation Child Job Definition（冻结）
 *
 * 对应迁移契约 docs/architecture/m-ai-06-review-card-child-job-contract.md
 *
 * 字段取值来源：
 * - promptKey/promptVersion: 复用现有 review-card-generation prompt（契约 §1.1.1）
 * - model: cheap tier（与旧 ReviewCardGenerationWorkflow 一致，契约 §1.1.1）
 * - queueName: ai-background（ReviewCard 不阻塞用户请求，契约 §5）
 * - input.schemaVersion: review-card-generation-v1（契约 §4）
 * - output.schemaVersion: review-card-generation-v1（契约 §5）
 * - timeoutMs: 120000（2min，卡片生成比 Feynman 评估更快）
 * - maxRetries: 3（与 Feynman/ActiveRecall 一致）
 * - cancellable: true（支持取消）
 * - domain: generation（区别于 analysis）
 */

export const REVIEW_CARD_GENERATION_JOB_DEFINITION: JobDefinition = {
  jobType: 'review_card_generation',

  metadata: {
    label: 'ReviewCard Generation',
    description:
      'Generate spaced-repetition review cards from Feynman evaluation results. ' +
      'Uses the learning content (summary, strengths, weaknesses) to create ' +
      'question-answer card pairs optimized for active recall.',
    domain: 'generation',
    version: '1.0.0',
  },

  queue: {
    queueName: 'ai-background',
    defaultPriority: 0,
  },

  execution: {
    timeoutMs: 120_000,       // 2 min — card generation is faster than full evaluation
    maxRetries: 3,            // Match existing Job types
    retryBackoff: { type: 'exponential', delay: 1000 },
    cancellable: true,
    abortStrategy: 'fail',    // Fail on timeout; retry logic handles retry
  },

  input: {
    schemaVersion: 'review-card-generation-v1',
  },

  output: {
    schemaVersion: 'review-card-generation-v1',
  },

  prompt: {
    promptKey: 'review-card-generation',
    promptVersion: '1.0.0',
  },

  model: {
    modelTier: 'cheap',
    modelProvider: 'deepseek',
    modelName: 'deepseek-v4-flash',  // Must match ModelRouter DEFAULT_ROUTES.cheap (model-router.ts:20)
    maxTokens: 2048,                 // Card generation needs fewer tokens than evaluation
  },

  credential: {
    allowedModes: ['platform_key'],
    defaultMode: 'platform_key',
  },

  projectorKey: 'review_card_generation_projector',

  security: {
    contentSafetyCheck: true,
    outputRedaction: false,
  },
};
