import { BaseDataManager } from './baseDataManager';
import { convertCamelCaseToSnakeCase } from '../utilities/functions';
import { capitalize } from 'lodash';

export default class UserDataManager extends BaseDataManager {
  static formatRequestObject(user) {
    const { orderBy, roles, ...rest } = user || {};
    return {
      ...rest,
      ...(orderBy?.id && { orderBy: `${orderBy?.desc ? '-' : ''}${convertCamelCaseToSnakeCase(orderBy?.id)}` }),
      ...(roles?.length && { roles: roles.map((role) => role.value) }),
    };
  }

  static formatResponseObject(user) {
    const { createdAt, updatedAt, roles, ...rest } = user;
    return {
      ...rest,
      ...(createdAt && { createdAt: new Date(createdAt) }),
      ...(updatedAt && { updatedAt: new Date(updatedAt) }),
      ...(roles?.length > 0 && {
        roles: roles.map((role) => {
          console.log({ role });
          return {
            label: capitalize(role?.name),
            value: role?.id,
          };
        }),
      }),
    };
  }
}
