<?php

namespace App\Services\Admin\Auth;

use App\libs\Response\GlobalApiResponse;
use App\libs\Response\GlobalApiResponseCodeBook;
use App\Services\BaseService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;

class ForgotPasswordService extends BaseService
{
    public function sendResetLinkEmail($data)
    {
        $response = $this->broker()->sendResetLink(
            $data->only('email')
        );

        return $response == Password::RESET_LINK_SENT
            ? (new GlobalApiResponse())->success('A password reset link sent to your email, please click on that link to reset your password.', 1)
            : (new GlobalApiResponse())->error(GlobalApiResponseCodeBook::RECORD_NOT_EXIST, "No user found with this email");
    }

    /**
     * Get the broker to be used during password reset.
     *
     * @return \Illuminate\Contracts\Auth\PasswordBroker
     */
    public function broker()
    {
        return Password::broker();
    }
}
