public PokerHandType determineHandType(FiveCardPokerHand hand) {
        if (hand.getNumberOfCards() != 5) {
            throw new IllegalArgumentException("The hand must have exactly five cards");
        }

        List<Card> cards = hand.getCards();

        Collections.sort(cards);

        // Check straight flush, flush and straight
        boolean isFlush = isFlush(cards);
        boolean isStraight = isStraight(cards);

        if (isFlush && isStraight) {
            return PokerHandType.STRAIGHT_FLUSH;
        }
        if (isFlush) {
            return PokerHandType.FLUSH;
        }
        if (isStraight) {
            return PokerHandType.STRAIGHT;
        }
        List<Integer> cardsOfSameRankList = cardsOfSameRankList(cards);

        // Four of a kind
        if (cardsOfSameRankList.get(0) == 4) {
            return PokerHandType.FOUR_OF_A_KIND;
        }
        // Full house and three of a kind
        if (cardsOfSameRankList.get(0) == 3) {
            if (cardsOfSameRankList.get(1) == 2) {
                return PokerHandType.FULL_HOUSE;
            }
            return PokerHandType.THREE_OF_A_KIND;
        }
        // Two pair and pair
        if (cardsOfSameRankList.get(0) == 2) {
            if (cardsOfSameRankList.get(1) == 2) {
                return PokerHandType.TWO_PAIR;
            }
            return PokerHandType.PAIR;
        }

        // If none of the above are true, the hand is a high card hand.
        return PokerHandType.HIGH_CARD;
    }