import { PersonalDataType } from '@sky-distribution/policy-service-interfaces/lib/common/PersonalData.type'; import { AddressDataType } from '@sky-distribution/policy-service-interfaces/lib/common/AddressData.type'; import { AccountHolderType } from '@sky-distribution/policy-service-interfaces/lib/core/SubmissionForm.type'; import { buildDatePartial } from './date'; import { buildAddressPartial } from './address'; import { CoreRequestDefaults } from '../utils/DefaultValues'; import { getMaritalStatusCode } from '../utils/baseData.util'; export type AccountHolderPartialInput = { personalData?: PersonalDataType; addressData?: AddressDataType; additionalAddresses?: AddressDataType; }; export const buildAccountHolderPartial = ( inputData?: AccountHolderPartialInput, ): AccountHolderType => ({ ...(inputData && inputData.personalData && inputData.personalData.name && inputData.personalData.surname && { displayName: `${inputData.personalData.name.toUpperCase()} ${inputData.personalData.surname.toUpperCase()}`, }), maritalStatus: getMaritalStatusCode(inputData?.personalData?.maritalStatus), subtype: 'Person', accountHolder: true, firstName: inputData?.personalData?.name ?? CoreRequestDefaults.PERSONAL_DATA.NAME, lastName: inputData?.personalData?.surname ?? CoreRequestDefaults.PERSONAL_DATA.SURNAME, primaryAddress: buildAddressPartial(inputData?.addressData), ...(inputData?.additionalAddresses?.street ? { additionalAddresses: [buildAddressPartial(inputData?.additionalAddresses)] ?? [], } : {}), dateOfBirth: buildDatePartial(inputData?.personalData?.birthDate), emailAddress1: inputData?.personalData?.email, homeNumber: inputData?.personalData?.phone, // eslint-disable-next-line @typescript-eslint/naming-convention pesel_SKY: inputData?.personalData?.pesel, ...(inputData?.personalData?.publicID && { publicID: inputData?.personalData?.publicID, }), ...(inputData?.personalData?.accountNumber && { accountNumber: inputData?.personalData?.accountNumber, }), ...(inputData?.personalData?.ufgData && { // eslint-disable-next-line @typescript-eslint/naming-convention ufgData_SKY: inputData?.personalData?.ufgData, }), });