<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;

class SetUserPasswordCommand extends Command
{
    protected $signature = 'user:set-password {email : The user email address} {password : The new plain-text password}';

    protected $description = 'Set a user password with a fresh Bcrypt hash';

    public function handle(): int
    {
        $user = User::query()->where('email', $this->argument('email'))->first();

        if ($user === null) {
            $this->error('No user found for that email.');

            return self::FAILURE;
        }

        $user->forceFill([
            'password' => $this->argument('password'),
        ])->save();

        $this->info("Password updated for {$user->email}.");

        return self::SUCCESS;
    }
}
