<?php

namespace App\Classes\Modules\Accounts\Services;


use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Models\PasswordReset;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class GeneratesPasswordReset extends AbstractUpdateRelationshipRecord
{

    /**
     * @param User $user
     * @return \Illuminate\Database\Eloquent\Model
     * @throws MalformedRequestException
     */
    public function execute(User $user): Model {
        $model = new PasswordReset();
        $model->token = Str::random(60);
        $model->is_expired = false;
        $model->is_complete = false;

        return $this->handler($user->passwordReset(), $model);
    }

}