import { PatientSource } from '@prisma/client';
import { fakerDE as faker } from '@faker-js/faker';
import { isValidDate } from 'src/utils';
import { PatientPreStaging } from '../staging.interface';
import {
  parseDateTime,
  pick,
  transformProperties,
} from '../transformer.functions';

export class PatientTransformer {
  public static transform(patientSource: PatientSource): PatientPreStaging {
    const patientParsed = {
      ...patientSource,
      // surname: faker.person.lastName(),
      // name: faker.person.firstName(),
      // street: faker.location.streetAddress(),
      ...transformProperties(parseDateTime('yyyy-MM-dd'))(
        pick(['birthday'])(patientSource),
      ),
    };

    const {
      id,
      surname,
      name,
      street,
      zip,
      city,

      birthday,
      kkId,
      krankenkasse,
      pflegestufe,
      behinderung1,
      behinderung2,
    } = patientParsed;

    return {
      id,
      surname,
      name,
      street,
      zip,
      city,
      birthday: isValidDate(new Date(birthday)) ? birthday : undefined,
      healthinsurance: krankenkasse,
      healthinsuranceId: kkId,
      careDegree: pflegestufe,
      disabilityMark1: behinderung1,
      disabilityMark2: behinderung2,
    } as unknown as PatientPreStaging;
  }
}
