<?php
namespace App\Models;

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

use App\Notifications\UserRegistered;

trait ForcedPassword
{
    public function setForcedPassword($sendToEmail = true)
    {
        $newPassword = Str::password(8);
        $this->password = Hash::make($newPassword);
        $this->save();
        if ($sendToEmail)
        {
            $this->notify(instance: new UserRegistered($this->email, password: $newPassword));
        }
        return $newPassword;
    }
}