import type { UserManagementRecord } from "@/types/user-management";

type SerializableUser = {
  id: bigint;
  name: string;
  email: string | null;
  username: string | null;
  phone: string | null;
  status: string;
  emailVerifiedAt: Date | null;
  createdAt: Date;
  updatedAt: Date;
  role: {
    id: bigint;
    code: string;
    name: string;
  };
};

export function serializeUser(user: SerializableUser): UserManagementRecord {
  return {
    id: user.id.toString(),
    name: user.name,
    email: user.email,
    username: user.username,
    phone: user.phone,
    status: user.status,
    role: {
      id: user.role.id.toString(),
      code: user.role.code,
      name: user.role.name
    },
    email_verified_at: user.emailVerifiedAt?.toISOString() ?? null,
    created_at: user.createdAt.toISOString(),
    updated_at: user.updatedAt.toISOString()
  };
}
