import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:niogu_ecommerce_v1/features/favorite/domain/entities/favorite.dart';
import 'package:niogu_ecommerce_v1/features/home/domain/entities/home.dart';

class FavoriteController extends StateNotifier<Map<String, SelectedFavorite>> {
  FavoriteController() : super({});

  void toggle(ProductItem product, String outletId) {
    final key = "$outletId-${product.id}";
    if (state.containsKey(key)) {
      state = {...state}..remove(key);
    } else {
      state = {
        ...state,
        key: SelectedFavorite(
          id: product.id,
          image: product.image,
          outletId: outletId,
          name: product.name,
          totalSold: product.totalSold,
          averageRating: product.averageRating,
          sellingPrice: product.sellingPrice,
          likes: product.likes,
        ),
      };
    }
  }
}
