<?php

namespace App\Jobs;


use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Support\Facades\Password;
use Illuminate\Http\Request;

class SendResetPassword extends Job implements ShouldQueue, JobEmailSender
{
    use InteractsWithQueue, SerializesModels, ResetsPasswords;

    protected $data;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->subject = trans('passwords.subject');
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $broker = $this->getBroker();
        
        $response = Password::broker($broker)->sendResetLink(
            ['email'=>$this->data['email']],
            $this->resetEmailBuilder()
        );
        switch ($response) {
            case Password::RESET_LINK_SENT:
                return $this->getSendResetLinkEmailSuccessResponse($response);
            case Password::INVALID_USER:
            default:
                return $this->getSendResetLinkEmailFailureResponse($response);
        }
    }
    /**
     * Show user email
     * @return string
     */
    public function getUserEmail(){
        return $this->data['email'];
    }

}
