<?php

namespace App\Support;

use App\Models\AdminUser;

/** 管理员用户 API 中列表行 / 详情 / 变更成功后的统一 JSON 形状。 */
final class AdminUserApiPresenter
{
    /** @return array<string, mixed> */
    public static function listItem(AdminUser $user): array
    {
        $user->loadMissing('roles');
        $siteBindings = AdminUserSiteBindingPresenter::bindingsFor($user);

        return [
            'id' => (int) $user->id,
            'username' => $user->username,
            'nickname' => $user->name,
            'email' => $user->email,
            'status' => (int) $user->status,
            'account_kind' => $user->isPlatformAccount() ? 'platform' : 'agent',
            'roles' => $user->adminRoleSlugs(),
            'site_bindings' => $siteBindings,
            'direct_permissions' => $user->directLegacyPermissionSlugs(),
            'effective_permissions' => $user->adminPermissionSlugs(),
        ];
    }
}
