const { getPool } = require('./userModel'); async function findAll({ search, is_active } = {}) { const db = getPool(); let sql = 'SELECT * FROM partner_companies WHERE 1=1'; const params = []; if (is_active !== undefined) { sql += ' AND is_active = ?'; params.push(is_active); } if (search) { sql += ' AND (company_name LIKE ? OR business_number LIKE ?)'; params.push(`%${search}%`, `%${search}%`); } sql += ' ORDER BY company_name'; const [rows] = await db.query(sql, params); return rows; } async function findById(id) { const db = getPool(); const [rows] = await db.query('SELECT * FROM partner_companies WHERE id = ?', [id]); return rows[0] || null; } async function findWorkersByCompany(companyId) { const db = getPool(); const [rows] = await db.query( 'SELECT * FROM partner_workers WHERE company_id = ? ORDER BY is_team_leader DESC, worker_name', [companyId] ); return rows; } module.exports = { findAll, findById, findWorkersByCompany };