import prisma from '../src/lib/prisma'
import { decrypt } from '../src/lib/crypto'

async function main() {
  // 查找刘洋
  const employees = await prisma.employee.findMany({
    select: { id: true, name: true, birthDate: true, retirementDaysLeft: true, gender: true, idCardNumber: true },
  })
  for (const emp of employees) {
    let idCard = ''
    if (emp.idCardNumber) {
      try { idCard = decrypt(emp.idCardNumber).toString() } catch {}
    }
    console.log(`${emp.name} | birthDate=${emp.birthDate?.toISOString().slice(0,10) || 'NULL'} | retirementDaysLeft=${emp.retirementDaysLeft ?? 'NULL'} | gender=${emp.gender} | idCard=${idCard.slice(0,6)}...`)
  }

  // 查找刘洋的合同
  const liu = employees.find(e => e.name === '刘洋')
  if (liu) {
    const contracts = await prisma.contract.findMany({ where: { employeeId: liu.id }, select: { contractType: true, status: true } })
    console.log('\n刘洋合同:', contracts)
  }

  // 查找已确认政策
  const policies = await prisma.retirementPolicy.findMany({ select: { id: true, version: true, status: true, maleRetireAge: true, femaleRetireAge: true, femaleWorkerAge: true } })
  console.log('\n政策:', policies)

  await prisma.$disconnect()
}
main()
