import 'package:bloc/bloc.dart';
import 'package:easycook_mobile/models/supplier.dart';
import 'package:easycook_mobile/repositories/supplier_repository.dart';
import 'package:equatable/equatable.dart';

part 'supplier_state.dart';

class SupplierCubit extends Cubit<SupplierState> {
  SupplierCubit() : super(SupplierInitial());

  final SupplierRepositories _supplierRepositories = SupplierRepositories();

  Future<void> supplier({required int id}) async {
    emit(SupplierLoading());
    try {
      final response = await _supplierRepositories.getSupplier(id);
      emit(SupplierSuccess(supplier: response.data));
    } catch (error) {
      emit(SupplierFailure(message: error.toString()));
    }
  }
}
