import 'package:flutter_test/flutter_test.dart';
import 'package:werwolf/models/game.dart';
import 'package:werwolf/models/player.dart';
import 'package:werwolf/models/role.dart';

void main() {
  group('Game Tests', () {
    List<String> playerNames = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve', 'Frank'];

    test('Initial number of wolves is 1', () {
      Game game = Game(playernames: playerNames);
      expect(game.getWolves(), 1);
    });

    test('Increment wolves within valid range', () {
      Game game = Game(playernames: playerNames);
      game.incrementWolves();
      expect(game.getWolves(), 2);
    });

    test('Decrement wolves within valid range', () {
      Game game = Game(playernames: playerNames);
      game.incrementWolves();
      game.decrementWolves();
      expect(game.getWolves(), 1);
    });

    test('Cannot increment wolves beyond valid range', () {
      Game game = Game(playernames: playerNames);
      game.incrementWolves();
      game.incrementWolves();
      expect(game.getWolves(), 2);  // Should not increment beyond 2 for 6 players
    });

    test('Cannot decrement wolves below 1', () {
      Game game = Game(playernames: playerNames);
      game.decrementWolves();
      expect(game.getWolves(), 1);  // Should not decrement below 1
    });

    test('Assign roles to players correctly', () {
      Game game = Game(playernames: playerNames);
      List<Player> players = game.getAllPlayers();
      expect(players.length, playerNames.length);
      int wolfCount = players.where((p) => p.role == Role.werwolf).length;
      int dorfbewohnerCount = players.where((p) => p.role == Role.dorfbewohner).length;
      expect(wolfCount, game.getWolves());
      expect(dorfbewohnerCount, playerNames.length - game.getWolves() - game.specialRoles.values.where((v) => v).length);
    });

    test('Special roles are assigned correctly', () {
      Game game = Game(playernames: playerNames);
      game.specialRoles[Role.seher] = true;
      List<Player> players = game.getAllPlayers();
      int seherCount = players.where((p) => p.role == Role.seher).length;
      expect(seherCount, 1);
    });

    test('Multiple special roles assignment', () {
      Game game = Game(playernames: playerNames);
      game.specialRoles[Role.seher] = true;
      game.specialRoles[Role.joker] = true;
      List<Player> players = game.getAllPlayers();
      int seherCount = players.where((p) => p.role == Role.seher).length;
      int jokerCount = players.where((p) => p.role == Role.joker).length;
      expect(seherCount, 1);
      expect(jokerCount, 1);
    });

    test('Minimum number of players', () {
      List<String> minPlayerNames = ['Alice', 'Bob', 'Charlie'];
      Game game = Game(playernames: minPlayerNames);
      List<Player> players = game.getAllPlayers();
      expect(players.length, minPlayerNames.length);
    });

    test('Maximum number of players (arbitrary large number)', () {
      List<String> maxPlayerNames = List<String>.generate(100, (index) => 'Player$index');
      Game game = Game(playernames: maxPlayerNames);
      List<Player> players = game.getAllPlayers();
      expect(players.length, maxPlayerNames.length);
    });
  });
}
