<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\ResetUserTwoFactorRequest;
use App\Models\PortalUser;
use App\Services\TwoFactorAuthService;
use Illuminate\Http\JsonResponse;

class TwoFactorController extends Controller
{
    public function __construct(
        private readonly TwoFactorAuthService $twoFactorService
    ) {
    }

    /**
     * Reset 2FA for a portal user (admin action).
     */
    public function resetPortalUserTwoFactor(ResetUserTwoFactorRequest $request): JsonResponse
    {
        $portalUser = PortalUser::findOrFail($request->validated('user_id'));

        $this->twoFactorService->resetTwoFactor($portalUser);

        return response()->json([
            'success' => true,
            'message' => 'Two-factor authentication has been reset for this user. They will be prompted to set it up on their next login.',
        ]);
    }
}
