<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

class AdminUserSeeder extends Seeder
{
    public function run(): void
    {
        $now = now();

        DB::table('admin_users')->updateOrInsert(
            ['username' => 'admin'],
            [
                'password' => Hash::make('admin123'),
                'name' => '超级管理员',
                'email' => null,
                'phone' => null,
                'avatar' => null,
                'status' => 1,
                'last_login_at' => null,
                'last_login_ip' => null,
                'login_count' => 0,
                'password_changed_at' => null,
                'create_time' => $now,
                'update_time' => $now,
            ]
        );

        $adminUser = DB::table('admin_users')->where('username', 'admin')->first();

        DB::table('admin_user_roles')->updateOrInsert(
            ['user_id' => $adminUser->id, 'role_id' => 1],
            ['create_time' => $now, 'update_time' => $now]
        );
    }
}
