<?php

namespace App\Services\Quiz\Criteria;

use App\Enums\UserQuizStatusEnum;
use App\Models\User;

class FastCompletionAccuracy implements BadgeCriteriaInterface
{
    public function isMet(User $user, array $criteria): bool
    {
        $minScore = $criteria['value'] ?? 80;

        $fastest = $user->quizzes()
            ->where('score', '>=', $minScore)
            ->where('status', UserQuizStatusEnum::COMPLETED)
            ->orderBy('taken_time', 'asc')
            ->first();

        return ! is_null($fastest);
    }
}
