import '../database_helper.dart'; class OperadoresDao { final _db = DatabaseHelper.instance; Future>> getTodos() async { final db = await _db.db; return db.query('operadores', where: 'activo = 1', orderBy: 'nombre ASC'); } Future>> getEnTurno() async { final db = await _db.db; return db.query('operadores', where: 'activo = 1 AND en_turno = 1'); } Future insertar(String nombre, int nivel) async { final db = await _db.db; final iniciales = _calcularIniciales(nombre); return db.insert('operadores', { 'nombre': nombre, 'iniciales': iniciales, 'nivel': nivel, 'activo': 1, 'en_turno': 0, }); } Future setEnTurno(int id, bool valor) async { final db = await _db.db; return db.update( 'operadores', {'en_turno': valor ? 1 : 0}, where: 'id = ?', whereArgs: [id], ); } Future desactivar(int id) async { final db = await _db.db; return db.update('operadores', {'activo': 0}, where: 'id = ?', whereArgs: [id]); } String _calcularIniciales(String nombre) { final p = nombre.trim().split(RegExp(r'\s+')); if (p.length >= 2) return '${p.first[0]}${p.last[0]}'.toUpperCase(); return nombre.isNotEmpty ? nombre[0].toUpperCase() : '?'; } }