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

export default class RecordDataManager extends BaseDataManager {
  static formatRequestObject(record) {
    const { orderBy, ...rest } = record || {};
    return {
      ...rest,
      ...(orderBy?.id && { orderBy: `${orderBy?.desc ? '-' : ''}${convertCamelCaseToSnakeCase(orderBy?.id)}` }),
    };
  }

  static formatResponseObject(user) {
    const { scratchDatetime, dataJobHistories, createdAt, updatedAt, ...rest } = user;

    const test = {
      ...rest,
      ...(createdAt && { createdAt: new Date(createdAt) }),
      ...(updatedAt && { updatedAt: new Date(updatedAt) }),
      ...(scratchDatetime && { scratchDatetime: new Date(scratchDatetime) }),
      ...(dataJobHistories && {
        dataJobHistories: {
          ...dataJobHistories,
          ...(dataJobHistories?.createdAt && { createdAt: new Date(dataJobHistories?.createdAt) }),
          ...(dataJobHistories?.updatedAt && { updatedAt: new Date(dataJobHistories?.updatedAt) }),
        },
      }),
    };
    console.log({ test });
    return test;
  }
}
