<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Modules\OTPVerification\Rules\OTPVerificationRule;
use Illuminate\Http\Request;

class OTPVerificationController extends Controller
{
    public function index()
    {
        return view('pages.auth.otp-verify');
    }

    public function store(Request $request)
    {
        $request->validate([
            'code' => ['required', 'integer', new OTPVerificationRule(auth()->user()->phone_number)],
        ]);

        auth()->user()->update([
            'phone_number_verified_at' => now(),
        ]);

        return redirect('/');
    }
}
