import { WorkTimeSource } from '@prisma/client';
import { fakerDE as faker } from '@faker-js/faker';
import { WorkTimePreStaging } from '../staging.interface';
import {
  parseCETDateTime,
  parseInteger,
  pick,
  transformProperties,
} from '../transformer.functions';

export class WorkTimeTransformer {
  public static transform(workTimeSource: WorkTimeSource): WorkTimePreStaging {
    const workTimeParsed = {
      ...workTimeSource,
      // firstname: faker.person.firstName(),
      // surname: faker.person.lastName(),
      ...transformProperties(parseInteger)(
        pick(['id', 'user_id'])(workTimeSource),
      ),
      ...transformProperties(parseCETDateTime('yyyy-MM-dd HH:mm:ss'))(
        pick(['start_date', 'end_date'])(workTimeSource),
      ),
    };

    const {
      id,
      user_id,
      firstname,
      surname,
      department_name,
      start_date,
      end_date,
    } = workTimeParsed;

    return {
      id,
      firstname,
      surname,
      employeeId: user_id,
      departmentName: department_name,
      startDate: start_date,
      endDate: end_date,
    } as unknown as WorkTimePreStaging;
  }
}
