import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart';
import 'package:enaklo_pos/data/models/response/payment_method_response_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'payment_method_report_event.dart';
part 'payment_method_report_state.dart';
part 'payment_method_report_bloc.freezed.dart';

class PaymentMethodReportBloc
    extends Bloc<PaymentMethodReportEvent, PaymentMethodReportState> {
  final OrderRemoteDatasource datasource;
  PaymentMethodReportBloc(this.datasource) : super(const _Initial()) {
    on<_GetPaymentMethodReport>((event, emit) async {
      emit(const _Loading());
      final result = await datasource.getPaymentMethodByRangeDate(
        event.startDate,
        event.endDate,
      );

      result.fold((l) => emit(_Error(l)), (r) => emit(_Loaded(r.data!)));
    });
  }
} 