export const meta = {
  name: 'improve-journal-club',
  description: '完善 Journal Club: attendance 模型/API, stats 统计, 前端增强',
  phases: [
    { title: 'Backend Model', detail: 'Attendance 模型 + 迁移' },
    { title: 'Backend API', detail: 'Stats + archive presenter + attendance CRUD + tenant fix' },
    { title: 'Frontend', detail: 'Stats cards / links / attendance / 日历交互' },
  ],
}

phase('Backend Model')
const m1 = await agent(
  "Add JournalClubAttendance model to backend/models/team.py, export in __init__.py, then auto-generate and apply alembic migration. The model has id (UUID PK), tenant_id (FK tenants), queue_id (FK journal_club_queue), user_id (FK users), attended (Boolean default true), rating (Integer nullable, 1-5), comment (Text nullable), created_at (timestamptz). Write files with Edit/Write tool, then run alembic revision --autogenerate and upgrade head. Verify the table was created.",
  {label: 'model+migration', schema: {type: 'object', properties: {ok: {type: 'boolean'}}, required: ['ok']}}
)

phase('Backend API')
const m2 = await agent(
  "Enhance the journal club API at backend/app/api/v1/journal_club.py. The JournalClubAttendance model now exists in app.models.team. User model is in app.models.user. " +
  "Changes needed: 1) Add GET /stats endpoint returning queued_count, presented_this_month, total_archived, monthly_counts (last 6 months by to_char), top_presenters (top 5 by count). " +
  "2) Enhance GET /archive to include presenter_name by outerjoin to User table. " +
  "3) Add POST /journal-club/queue/{jid}/attendance (upsert by queue_id+user_id, takes rating 1-5 and comment), GET /journal-club/queue/{jid}/attendance (returns attendees with display_name), DELETE /journal-club/queue/{jid}/attendance (remove current user). " +
  "4) Fix tenant isolation: add tenant_id filter to decide_article, update_notes, remove_from_queue, update_queue_item (add .where to select). " +
  "After changes, run: cd d:/ClaudeCode/backend && python -m pytest tests/test_journal_club.py -v --no-cov 2>&1 | tail -30",
  {label: 'api-enhance', schema: {type: 'object', properties: {ok: {type: 'boolean'}, test_summary: {type: 'string'}}, required: ['ok', 'test_summary']}}
)

phase('Frontend')
const m3 = await agent(
  "Enhance the Journal Club frontend at frontend/src/views/app/JournalClubView.vue. Read the file first. " +
  "Changes: 1) Add stats cards section (between header/alert and tabs) showing queued_count, presented_this_month, total_archived from a new GET /journal-club/stats API call. Add to Promise.all in loadData. " +
  "2) Make literature titles clickable (RouterLink to /app/literature/:pmid) in the DataTable columns. Import RouterLink from vue-router. " +
  "3) Show presenter_name in archive column (already partially works with members list, also use r.presenter_name). " +
  "4) Add attendance modal: in archive tab action column for presented items, add an attendance button that opens a modal with attendee list, star rating (1-5 buttons), and comment input. Call POST/DELETE /journal-club/queue/{jid}/attendance. GET the attendance list from /journal-club/queue/{jid}/attendance. " +
  "5) Calendar day click: add @click on cal-cell div that opens a modal showing all items for that day. " +
  "6) After AI outline generates, add a save-to-notes button that fills the notes drawer with the outline content. " +
  "Run: cd d:/ClaudeCode/frontend && npm run build. Fix any TS errors.",
  {label: 'frontend-enhance', schema: {type: 'object', properties: {ok: {type: 'boolean'}, build_output: {type: 'string'}}, required: ['ok', 'build_output']}}
)

return {model: m1, api: m2, frontend: m3}
