part of 'services_bloc.dart'; sealed class ServicesState extends Equatable { ServicesState({final List lockedServices = const []}) : _lockedServices = lockedServices.where((final lock) => lock.isLocked).toList(); final List _lockedServices; List get services; List get lockedServices => _lockedServices .where((final lock) => lock.isLocked) .map((final lock) => lock.serviceId) .toList(); List get servicesThatCanBeBackedUp => services .where( (final service) => service.canBeBackedUp, ) .toList(); bool isServiceLocked(final String serviceId) => lockedServices.contains(serviceId); Service? getServiceById(final String id) { final service = services.firstWhere( (final service) => service.id == id, orElse: () => Service.empty, ); if (service.id == 'empty') { return null; } return service; } ServicesState copyWith({ final List? services, final List? lockedServices, }); } class ServiceLock extends Equatable { ServiceLock({ required this.serviceId, required this.lockDuration, }) : lockTime = DateTime.now(); final String serviceId; final Duration lockDuration; final DateTime lockTime; bool get isLocked => DateTime.now().isBefore(lockTime.add(lockDuration)); @override List get props => [serviceId, lockDuration, lockTime]; } class ServicesInitial extends ServicesState { @override List get props => []; @override List get services => []; @override ServicesState copyWith({ final List? services, final List? lockedServices, }) => ServicesInitial(); } class ServicesLoaded extends ServicesState { ServicesLoaded({ required final List services, required super.lockedServices, }) : _servicesHachCode = Object.hashAll([...services]); final int _servicesHachCode; final apiConnectionRepository = getIt(); List get _services => apiConnectionRepository.apiData.services.data ?? []; @override List get services => _services; @override List get props => [_servicesHachCode, _lockedServices]; @override ServicesLoaded copyWith({ final List? services, final List? lockedServices, }) => ServicesLoaded( services: services ?? this.services, lockedServices: lockedServices ?? _lockedServices, ); } class ServicesReloading extends ServicesLoaded { ServicesReloading({ required super.services, required super.lockedServices, }); ServicesReloading.fromState(final ServicesLoaded state) : super( services: state.services, lockedServices: state._lockedServices, ); @override List get props => [services, lockedServices]; }