import type { AdminUserView } from "@batch-cooking/shared";
import type { AdminUser } from "@prisma/client";

/**
 * Shapes a Prisma `AdminUser` into the {@link AdminUserView} sent to the
 * admin client — drops `passwordHash` **and** `tokenVersion` (an internal
 * invalidation counter the client never needs, unlike `SafeUserProfile`
 * which does expose it), and serializes the two dates to ISO strings. The
 * one place this security-relevant stripping happens, same role as
 * `toSafeProfile` (`lib/safe-profile.ts`).
 */
export function toSafeAdmin(admin: AdminUser): AdminUserView {
  return {
    id: admin.id,
    email: admin.email,
    name: admin.name,
    createdAt: admin.createdAt.toISOString(),
    lastLoginAt: admin.lastLoginAt === null ? null : admin.lastLoginAt.toISOString(),
  };
}
