import 'package:bloc/bloc.dart';
import 'package:dio/dio.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:hoshan/data/repository/paymant_repository.dart';

part 'settlement_state.dart';

class SettlementCubit extends Cubit<SettlementState> {
  SettlementCubit() : super(SettlementInitial());

  void init(bool isRial) async {
    emit(SettlementLoading());
    try {
      final message = await PaymantRepository.setSettlement(isRial);
      emit(SettlementSuccess(message: message));
    } on DioException catch (e) {
      emit(SettlementFail(message: e.response?.data['detail']));
      if (kDebugMode) {
        print('Dio Error is: $e');
      }
    }
  }
}
