import 'package:flutter_bloc/flutter_bloc.dart'; import '../domain/repositories/sos_repository.dart'; enum SosPhase { idle, sending, sent, error } class SosState { final SosPhase phase; final String? message; const SosState({this.phase = SosPhase.idle, this.message}); } class SosCubit extends Cubit { final SosRepository _repository; SosCubit(this._repository) : super(const SosState()); Future trigger({ String triggerType = 'MANUAL', double? lat, double? lng, }) async { emit(const SosState(phase: SosPhase.sending)); final result = await _repository.triggerSos( triggerType: triggerType, lat: lat, lng: lng, ); result.fold( (failure) => emit(SosState(phase: SosPhase.error, message: failure.message)), (_) => emit(const SosState( phase: SosPhase.sent, message: 'SOS terkirim. Guardian sudah diberi tahu.', )), ); } }