/**
 * 4분면 보드 section 정렬 — 조직문화(EX) 프로젝트 재배치
 * npx tsx scripts/migrate-board-sections.ts
 */
import 'dotenv/config';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

const EX_TITLE = /회사생활|C\.E\.L|조직문화|복리후생|문화\s*진단|직원\s*소통/i;

async function main() {
  const tasks = await prisma.task.findMany({
    select: { id: true, title: true, section: true },
  });

  let moved = 0;
  for (const task of tasks) {
    if (task.section === '조직문화') continue;
    if (!EX_TITLE.test(task.title.trim())) continue;
    await prisma.task.update({
      where: { id: task.id },
      data: { section: '조직문화', category: '조직문화' },
    });
    moved += 1;
    console.log(`  → 조직문화: ${task.title}`);
  }

  const col = await prisma.columnConfig.findUnique({ where: { key: '운영관리' } });
  if (col && (col.title === '운영관리' || col.title === '운영관리 부문' || col.titleEn === 'Operations')) {
    await prisma.columnConfig.update({
      where: { key: '운영관리' },
      data: { title: '총무관리', titleEn: 'GA' },
    });
    console.log('  → column 운영관리 title → 총무관리');
  }

  console.log(`✅ migrate-board-sections complete (${moved} tasks moved)`);
}

main()
  .catch((err) => {
    console.error(err);
    process.exit(1);
  })
  .finally(() => prisma.$disconnect());
