<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Services\UserLookupService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class GuestVerificationResendController extends Controller
{
    /**
     * No auth middleware by design — a user whose session already expired
     * before they verified has no other way back in. Always responds the
     * same way regardless of whether the account exists or is already
     * verified, so this can't be used to enumerate registered emails.
     */
    public function store(Request $request, UserLookupService $lookup): JsonResponse
    {
        $request->validate([
            'login' => ['required', 'string'],
        ]);

        $user = $lookup->findByLogin($request->input('login'));

        if ($user && !$user->hasVerifiedEmail()) {
            $user->sendEmailVerificationNotification();
        }

        return response()->json([
            'message' => "If that account exists and needs verification, we've sent a new email.",
        ]);
    }
}
