import type User from '#models/user'
import { BaseTransformer } from '@adonisjs/core/transformers'

export default class UserTransformer extends BaseTransformer<User> {
  toObject() {
    return {
      ...this.pick(this.resource, [
        'id',
        'email',
        'username',
        'status',
        'dateOfBirth',
        'sex',
        'initials',
      ]),
      roles: this.resource.roles?.map((r) => r.name) ?? [],
      profileVisibility: this.resource.userPref?.profileVisibility ?? null,
      displayName: this.resource.userPref?.displayName ?? null,
      country: this.resource.userPref?.country ?? null,
      locale: this.resource.userPref?.locale ?? null,
    }
  }
}
