<?php

declare(strict_types=1);

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Services\OtpService;
use App\Services\UserService;
use App\Support\ApiResponse;
use Illuminate\Http\Request;

class ForgetController extends Controller
{
    /**
     * Handle the incoming request.
     */
    public function __invoke(Request $request, OtpService $otpService, UserService $userService)
    {
        $checkHashCode = $otpService->checkOtp($request->cellphone, $request->code);
        if (! $checkHashCode) {
            return ApiResponse::response(message: 'کد وارد شده صحیح نیست', status: 409);
        }

        return $userService->forgot($request);
    }
}
