import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import 'package:enaklo_pos/data/datasources/payment_methods_remote_datasource.dart';
import 'package:enaklo_pos/data/models/response/payment_methods_response_model.dart';

part 'payment_methods_event.dart';
part 'payment_methods_state.dart';
part 'payment_methods_bloc.freezed.dart';

class PaymentMethodsBloc extends Bloc<PaymentMethodsEvent, PaymentMethodsState> {
  final PaymentMethodsRemoteDatasource datasource;
  
  PaymentMethodsBloc(this.datasource) : super(const _Initial()) {
    on<_FetchPaymentMethods>((event, emit) async {
      emit(const _Loading());
      final response = await datasource.getPaymentMethods();
      response.fold(
        (l) => emit(_Error(l)),
        (r) => emit(_Loaded(r.data ?? [])),
      );
    });
  }
} 