import 'package:geolocator/geolocator.dart'; import '../../homes/services/location_platform_service.dart'; import '../models/geofence_system_state.dart'; abstract class GeofenceSystemStatusService { Future inspect({ required bool hasActiveHome, required bool hasCoordinates, }); } class DeviceGeofenceSystemStatusService implements GeofenceSystemStatusService { final LocationPlatformService locationPlatformService; DeviceGeofenceSystemStatusService({required this.locationPlatformService}); @override Future inspect({ required bool hasActiveHome, required bool hasCoordinates, }) async { if (!hasActiveHome) { return const GeofenceSystemState(GeofenceSystemIssue.noActiveHome); } if (!hasCoordinates) { return const GeofenceSystemState(GeofenceSystemIssue.missingCoordinates); } if (!await locationPlatformService.isLocationServiceEnabled()) { return const GeofenceSystemState( GeofenceSystemIssue.locationServicesDisabled, ); } final permission = await locationPlatformService.checkPermission(); return switch (permission) { LocationPermission.denied => const GeofenceSystemState( GeofenceSystemIssue.permissionDenied, ), LocationPermission.deniedForever => const GeofenceSystemState( GeofenceSystemIssue.permissionDeniedForever, ), LocationPermission.whileInUse => const GeofenceSystemState( GeofenceSystemIssue.backgroundPermissionRequired, ), LocationPermission.always => const GeofenceSystemState( GeofenceSystemIssue.ready, ), _ => const GeofenceSystemState(GeofenceSystemIssue.permissionDenied), }; } }