import 'package:absenkuv3/Repository/Model/mValidasi.dart';
import 'package:absenkuv3/Repository/Service/patroliApi.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

abstract class CekValidasiWaktuEvent{}

class ChekValidasiWaktu extends CekValidasiWaktuEvent{
  String? waktu;
  ChekValidasiWaktu(this.waktu);
}

abstract class CekValidasiWaktuState{}
class ChekValidasiProgress extends CekValidasiWaktuState{}
class ChekValidasiSuccess extends CekValidasiWaktuState{
  ValidasiWaktu checkvalidasiwaktu;
  ChekValidasiSuccess(this.checkvalidasiwaktu);
}
class CekValidasiNovalid extends CekValidasiWaktuState{}

class CekValidasiError extends CekValidasiWaktuState{}
class CekValidasiWaktuBloc extends Bloc<CekValidasiWaktuEvent,CekValidasiWaktuState>{
  CekValidasiWaktuBloc(CekValidasiWaktuState initialState):super(initialState);

  @override
  Stream<CekValidasiWaktuState> mapEventToState(CekValidasiWaktuEvent event)async*{
    if ( event is ChekValidasiWaktu){
      yield ChekValidasiProgress();
      ValidasiWaktu checkvalidasiwaktu = await PatroliApi().cekWaktu(event.waktu);
      print(checkvalidasiwaktu.success!);
      if (checkvalidasiwaktu.success!)
      yield ChekValidasiSuccess(checkvalidasiwaktu);
      else if(checkvalidasiwaktu.success = false){
      // print("masuk");
      yield CekValidasiNovalid();
      }
      else yield CekValidasiError(

      );
    }
  }
}