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

export class PlannedTimeTransformer {
  public static transform(
    plannedTimeSource: PlannedTimeSource,
  ): PlannedTimePreStaging {
    const plannedTimeParsed = {
      ...plannedTimeSource,
      // firstname: faker.person.firstName(),
      // surname: faker.person.lastName(),
      ...transformProperties(parseInteger)(
        pick(['id', 'user_id'])(plannedTimeSource),
      ),
      ...transformProperties(parseCETDateTime('yyyy-MM-dd HH:mm:ss'))(
        pick(['start_date', 'end_date'])(plannedTimeSource),
      ),
      ...transformProperties(parseBoolean)(
        pick(['deleted'])(plannedTimeSource),
      ),
    };

    const {
      id,
      user_id,
      firstname,
      surname,
      department_name,
      start_date,
      end_date,
      deleted,
      mark,
    } = plannedTimeParsed;

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