import { EmployeeDyflexisSource } from '@prisma/client';

import { EmployeeDyflexisPreStaging } from '../staging.interface';
import {
  parseDateTime,
  parseFloat,
  parseInteger,
  pick,
  transformProperties,
} from '../transformer.functions';

export class DyflexisEmployeeTransformer {
  public static transform(
    dyflexisEmployeeSource: EmployeeDyflexisSource,
  ): EmployeeDyflexisPreStaging {
    const dyflexisEmployeeParsed = {
      ...dyflexisEmployeeSource,
      ...transformProperties(parseFloat)(
        pick(['contract_hours_week', 'contract_salary_hour'])(
          dyflexisEmployeeSource,
        ),
      ),
      ...transformProperties(parseInteger)(
        pick(['id'])(dyflexisEmployeeSource),
      ),
      ...transformProperties(parseDateTime('yyyy-MM-dd'))(
        pick(['contract_start', 'contract_end'])(dyflexisEmployeeSource),
      ),
    };

    const {
      id,
      firstname,
      surname,
      contract_start,
      contract_end,
      contract_hours_week,
      contract_salary_hour,
    } = dyflexisEmployeeParsed;

    return {
      id,
      firstname,
      surname,
      contractStart: contract_start,
      contractEnd: contract_end,
      contractHoursWeek: contract_hours_week,
      contractSalaryHour: contract_salary_hour,
    } as unknown as EmployeeDyflexisPreStaging;
  }
}
