<?php

namespace Database\Seeders;

use App\Models\AdminUser;
use Illuminate\Database\Seeder;
use App\Support\AdminAgentPermissionMenuActionSync;
use App\Support\AdminDrawPermissionMenuActionSync;
use App\Support\PlatformSystemRoles;
use App\Support\SuperAdminAccount;

/**
 * 后台 RBAC：平台固定角色 super_admin / agent。
 *
 * 演示账号 **admin** / **12345678**（仅限非 production）。
 */
final class AdminRbacAndUserSeeder extends Seeder
{
    public function run(): void
    {
        AdminAgentPermissionMenuActionSync::syncMissing();
        AdminDrawPermissionMenuActionSync::syncMissing();

        PlatformSystemRoles::ensureAll();

        $username = 'admin';
        AdminUser::query()->updateOrCreate(
            ['username' => $username],
            [
                'name' => '超级管理员',
                'email' => null,
                'password' => '12345678',
                'status' => 0,
            ],
        );

        /** @var AdminUser $admin */
        $admin = AdminUser::query()->where('username', $username)->firstOrFail();
        SuperAdminAccount::assign($admin);
    }
}
