const formatDateAsString = (value) =>
  value instanceof Date ? value.toISOString() : value ?? null

// adapters/responses/publicUser.adapter.js
function mapUserToPublicUserSummaryResponse(user) {
  return {
    id: user.id,
    username: user.username,
    avatarUrl: user.avatarUrl ?? null,
  }
}

function mapUserToPublicUserDetailsResponse(user) {
  return {
    id: user.id,
    username: user.username,
    avatarUrl: user.avatarUrl ?? null,
    email: user.email,
    createdAt: formatDateAsString(user.createdAt), // ISO string
  }
}

module.exports = {
  mapUserToPublicUserSummaryResponse,
  mapUserToPublicUserDetailsResponse,
}
