<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\User;
use Illuminate\Support\Facades\Hash;

class ResetUserPassword extends Command
{
    protected $signature = 'reset:password {email} {password}';
    protected $description = 'Reset user password';

    public function handle()
    {
        $email = $this->argument('email');
        $newPassword = $this->argument('password');
        
        $user = User::where('email', $email)->first();
        
        if (!$user) {
            $this->error("User with email {$email} not found");
            return;
        }
        
        $user->password = Hash::make($newPassword);
        $user->save();
        
        $this->info("Password reset successfully for {$user->name} ({$email})");
        $this->info("New password: {$newPassword}");
        
        // Test the new password immediately
        if (Hash::check($newPassword, $user->fresh()->password)) {
            $this->info("✅ Password verification successful!");
        } else {
            $this->error("❌ Password verification failed!");
        }
    }
}
