import 'dart:async';

import 'package:wyatt_bloc_layout/wyatt_bloc_layout.dart';

class ExampleCubit extends Cubit<CrudState> {
  ExampleCubit() : super(CrudInitial());

  FutureOr<void> run() async {
    while (true) {
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudLoading());
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudError('Cubit Error'));
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudLoaded<String>('DATA LOADED'));
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudInitial());
    }
  }

  FutureOr<void> runList() async {
    while (true) {
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudLoading());
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudError('Cubit Error'));
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudListLoaded<String>([
        'DATA LOADED 1',
        'DATA LOADED 2',
        'DATA LOADED 3',
        'DATA LOADED 4'
      ]));
      await Future.delayed(const Duration(seconds: 1));
      emit(CrudInitial());
    }
  }
}
