<?php

namespace App\Http\Controllers\Auth;

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

class OTPVericationController 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)],
        ]);

        User::find(auth()->id())->update([
            'phone_number_verified_at' => now(),
        ]);

        return redirect('/');
    }
}
