import 'package:block_seasons/data/save_repository.dart';
import 'package:block_seasons/game/models/booster.dart';
import 'package:block_seasons/state/booster_inventory_notifier.dart';
import 'package:block_seasons/state/providers.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  Future<ProviderContainer> container() async {
    SharedPreferences.setMockInitialValues({});
    final repo = SaveRepository(await SharedPreferences.getInstance());
    return ProviderContainer(
      overrides: [saveRepositoryProvider.overrideWithValue(repo)],
    );
  }

  test('exposes counts and updates on grant/consume', () async {
    final c = await container();
    final notifier = c.read(boosterInventoryProvider.notifier);

    expect(c.read(boosterInventoryProvider)[BoosterType.hammer], 0);

    await notifier.grant(BoosterType.hammer, 2);
    expect(c.read(boosterInventoryProvider)[BoosterType.hammer], 2);

    expect(await notifier.consume(BoosterType.hammer), isTrue);
    expect(c.read(boosterInventoryProvider)[BoosterType.hammer], 1);
  });
}
