const db = require('../config/db'); class Candidate { static async findAll() { const [rows] = await db.query('SELECT * FROM candidates'); return rows.map(row => ({ ...row, jobId: row.job_id, jobTitle: row.job_title, matchScore: row.match_score, highlights: JSON.parse(row.highlights || '[]'), concerns: JSON.parse(row.concerns || '[]'), skills: JSON.parse(row.skills || '[]'), submittedAt: row.submitted_at, reviewedAt: row.reviewed_at })); } static async findById(id) { const [rows] = await db.query('SELECT * FROM candidates WHERE id = ?', [id]); if (rows.length === 0) return null; const row = rows[0]; return { ...row, jobId: row.job_id, jobTitle: row.job_title, matchScore: row.match_score, highlights: JSON.parse(row.highlights || '[]'), concerns: JSON.parse(row.concerns || '[]'), skills: JSON.parse(row.skills || '[]'), submittedAt: row.submitted_at, reviewedAt: row.reviewed_at }; } static async findByJobId(jobId) { const [rows] = await db.query('SELECT * FROM candidates WHERE job_id = ?', [jobId]); return rows.map(row => ({ ...row, jobId: row.job_id, jobTitle: row.job_title, matchScore: row.match_score, highlights: JSON.parse(row.highlights || '[]'), concerns: JSON.parse(row.concerns || '[]'), skills: JSON.parse(row.skills || '[]'), submittedAt: row.submitted_at, reviewedAt: row.reviewed_at })); } static async updateStatus(id, status) { const [result] = await db.query( 'UPDATE candidates SET status = ?, reviewed_at = ? WHERE id = ?', [status, new Date(), id] ); if (result.affectedRows === 0) { throw new Error('Candidate not found'); } return this.findById(id); } static async batchUpdateStatus(candidateIds, status) { const [result] = await db.query( 'UPDATE candidates SET status = ?, reviewed_at = ? WHERE id IN (?)', [status, new Date(), candidateIds] ); return result.affectedRows; } } module.exports = Candidate;