import 'package:niogu_app/core/database/app_database.dart';
import 'package:niogu_app/core/network/dio_client.dart';
import 'package:niogu_app/core/services/sync_services.dart';
import 'package:workmanager/workmanager.dart';

@pragma('vm:entry-point')
void callbackDispatcher() {
  Workmanager().executeTask((taskName, inputData) async {
    final db = AppDatabase();
    
    final dio = DioClient().instance;

    final syncService = SyncService(dio, db);

    try {
      await syncService.processBatch(); 
      return Future.value(true);
    } catch (e) {
      return Future.value(false);
    } finally {
      await db.close();
    }
  });
}
