<?php

namespace App\Console\Commands;

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

class CheckUserDetails extends Command
{
    protected $signature = 'check:user {email}';
    protected $description = 'Check user details by email';

    public function handle()
    {
        $email = $this->argument('email');
        
        $user = User::where('email', $email)->first();
        
        if (!$user) {
            $this->error("User with email {$email} not found");
            return;
        }
        
        $this->info("User Details:");
        $this->info("Name: {$user->name}");
        $this->info("Email: {$user->email}");
        $this->info("ID: {$user->id}");
        $this->info("Status: {$user->status}");
        $this->info("Password Hash: " . substr($user->password, 0, 30) . "...");
        $this->info("Created: {$user->created_at}");
        $this->info("Updated: {$user->updated_at}");
        
        // Check customer relationship
        $customer = $user->customer;
        if ($customer) {
            $this->info("Customer ID: {$customer->id}");
            $this->info("Customer Name: {$customer->first_name} {$customer->last_name}");
            $this->info("Customer Created: {$customer->created_at}");
        } else {
            $this->info("No associated customer found");
        }
        
        // Test a few common passwords
        $testPasswords = ['test123', 'password', 'password123', '123456', 'admin123'];
        
        $this->info("\nTesting common passwords:");
        foreach ($testPasswords as $password) {
            if (Hash::check($password, $user->password)) {
                $this->info("✅ Password '{$password}' matches!");
                return;
            } else {
                $this->line("❌ Password '{$password}' does not match");
            }
        }
        
        $this->info("\nNone of the common passwords match.");
    }
}
