<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class TestUserSeeder extends Seeder
{
    public function run(): void
    {
        echo "Creating admin user...\n";
        DB::table('users')->insert([
            'name' => 'admin',
            'truename' => 'Administrator',
            'email' => 'admin@example.com',
            'role' => 'admin',
            'passwd' => \App\Helpers\PasswordHelper::encryptPassword('admin', '123456'),
            'creatime' => now(),
        ]);
        $adminID = DB::table('users')->where('name', 'admin')->value('ID');
        echo "Admin created - ID: {$adminID}\n";

        echo "Creating player1 user...\n";
        DB::table('users')->insert([
            'name' => 'player1',
            'truename' => 'Player One',
            'email' => 'player1@example.com',
            'role' => 'player',
            'passwd' => \App\Helpers\PasswordHelper::encryptPassword('player1', '123456'),
            'creatime' => now(),
        ]);
        $player1ID = DB::table('users')->where('name', 'player1')->value('ID');
        echo "Player1 created - ID: {$player1ID}\n";

        echo "Creating player2 user...\n";
        DB::table('users')->insert([
            'name' => 'player2',
            'truename' => 'Player Two',
            'email' => 'player2@example.com',
            'role' => 'player',
            'passwd' => \App\Helpers\PasswordHelper::encryptPassword('player2', '123456'),
            'creatime' => now(),
        ]);
        $player2ID = DB::table('users')->where('name', 'player2')->value('ID');
        echo "Player2 created - ID: {$player2ID}\n";

        echo "\nID increments by 16: " . ($player1ID - $adminID) . " and " . ($player2ID - $player1ID) . "\n";
        
        $admin = User::find($adminID);
        echo "Password verification test (admin/admin): ";
        echo $admin->checkPassword('admin') ? "PASS\n" : "FAIL\n";
        echo "Password hash: {$admin->passwd}\n";
    }
}
