import { AttendanceRegistrationSource } from '@prisma/client';
import { AttendanceRegistrationPreStaging } from '../staging.interface';
import {
  parseInteger,
  parseIsoDateTime,
  pick,
  transformProperties,
} from '../transformer.functions';

export class AttendanceRegistrationTransformer {
  public static transform(
    attendanceRegistrationSource: AttendanceRegistrationSource,
  ): AttendanceRegistrationPreStaging {
    const attendanceRegistrationParsed = {
      ...attendanceRegistrationSource,
      ...transformProperties(parseInteger)(
        pick(['attendanceRegistrationId', 'employeeId'])(
          attendanceRegistrationSource,
        ),
      ),
      ...transformProperties(parseIsoDateTime)(
        pick(['dateTime'])(attendanceRegistrationSource),
      ),
    };

    const { attendanceRegistrationId, employeeId, dateTime, event } =
      attendanceRegistrationParsed;

    return {
      attendanceRegistrationId,
      employeeId,
      dateTime,
      event,
    } as unknown as AttendanceRegistrationPreStaging;
  }
}
