import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

/**
 * Default position seeds
 */
export const POSITION_SEEDS = [
  {
    code: 'CEO',
    name: '首席执行官 (Chief Executive Officer)',
    level: 1,
    description: '公司最高管理者',
  },
  {
    code: 'CTO',
    name: '首席技术官 (Chief Technology Officer)',
    level: 1,
    description: '技术部门最高负责人',
  },
  {
    code: 'CFO',
    name: '首席财务官 (Chief Financial Officer)',
    level: 1,
    description: '财务部门最高负责人',
  },
  {
    code: 'COO',
    name: '首席运营官 (Chief Operating Officer)',
    level: 1,
    description: '运营部门最高负责人',
  },
  {
    code: 'VP',
    name: '副总裁 (Vice President)',
    level: 2,
    description: '公司高级管理层',
  },
  {
    code: 'DIR',
    name: '总监 (Director)',
    level: 3,
    description: '部门负责人',
  },
  {
    code: 'MGR',
    name: '经理 (Manager)',
    level: 4,
    description: '团队管理者',
  },
  {
    code: 'LEAD',
    name: '主管 (Team Lead)',
    level: 5,
    description: '小组负责人',
  },
  {
    code: 'SR_ENG',
    name: '高级工程师 (Senior Engineer)',
    level: 6,
    description: '资深技术人员',
  },
  {
    code: 'ENG',
    name: '工程师 (Engineer)',
    level: 7,
    description: '技术开发人员',
  },
  {
    code: 'JR_ENG',
    name: '初级工程师 (Junior Engineer)',
    level: 8,
    description: '初级技术人员',
  },
  {
    code: 'SPEC',
    name: '专员 (Specialist)',
    level: 7,
    description: '专业岗位人员',
  },
  {
    code: 'ASST',
    name: '助理 (Assistant)',
    level: 8,
    description: '辅助岗位人员',
  },
  {
    code: 'INTERN',
    name: '实习生 (Intern)',
    level: 9,
    description: '实习期人员',
  },
];

/**
 * Seed positions
 */
export async function seedPositions() {
  console.log('🌱 Seeding positions...');

  for (const positionSeed of POSITION_SEEDS) {
    await prisma.position.upsert({
      where: { code: positionSeed.code },
      update: {
        name: positionSeed.name,
        level: positionSeed.level,
        description: positionSeed.description,
      },
      create: {
        code: positionSeed.code,
        name: positionSeed.name,
        level: positionSeed.level,
        description: positionSeed.description,
      },
    });
  }

  console.log(`✅ Created ${POSITION_SEEDS.length} positions`);
}


if (require.main === module) {
  seedPositions()
    .then(() => { console.log('✅ Positions seed completed'); process.exit(0); })
    .catch((e) => { console.error('❌ Error seeding positions:', e); process.exit(1); })
    .finally(async () => { await prisma.$disconnect(); });
}
