import 'dart:async';

import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:krow/core/application/di/injectable.dart';
import 'package:krow/core/sevices/background_service/background_task.dart';
import 'package:krow/core/sevices/geofencing_serivce.dart';
import 'package:krow/features/shifts/domain/shifts_repository.dart';

class ContinuousClockoutCheckerTask implements BackgroundTask {
  @override
  Future<void> oneTime(ServiceInstance? service) async {
    // var shift = (await getIt<ShiftsRepository>()
    //         .getShifts(statusFilter: ShiftStatusFilterType.ongoing)
    //         .onError((error, stackTrace) {
    //   return [];
    // }))
    //     .firstOrNull;
    //
    // if (shift == null) {
    //   if (service is AndroidServiceInstance) {
    //     service.setAsBackgroundService();
    //   }
    //   return;
    // } else {
    //   GeofencingService geofencingService = getIt<GeofencingService>();
    //   try {
    //     var permission = await geofencingService.requestGeolocationPermission();
    //     if (permission == GeolocationStatus.enabled) {
    //       var inArea = await geofencingService.isInRangeCheck(
    //         pointLatitude: shift.locationLat,
    //         pointLongitude: shift.locationLon,
    //         range: 500,
    //       );
    //       if (!inArea) {
    //         await getIt<ShiftsRepository>().forceClockOut(shift.id);
    //       }
    //     }
    //   } catch (e) {}
    // }
  }

  @override
  Future<void> stop() async {}
}
