import { getAdditionalInfoData } from '../../retail/adaptors/getAdditionalInfoData'; import { getCardOptionsData } from '../../retail/adaptors/getCardOptionsData'; import { getEmploymentData } from '../../retail/adaptors/getEmploymentData'; import { getFamilyStatusAndIncomeData } from '../../retail/adaptors/getFamilyStatusAndIncomeData'; import { getPersonalInfoData } from '../../retail/adaptors/getPersonalInfoData'; import { type Participant, type UpdateUserTaskBody } from '../../retail/api/updateUserTask'; import { type LeadFormState } from '../../retail/model/LeadFormState'; import { checkNewMicroservice } from '../../retail/utils/checkNewMicroservice'; import { type Nullable } from '../../utils/Nullable'; import { getDeliveryCreditCardData, getDeliveryData, getOfficeCode, } from './getDeliveryCreditCardData'; type getCreditCardFormTaskDataProps = { participantId: Nullable; taskId: number; profileId: Nullable; formData: LeadFormState; step?: number; }; export const getCreditCardFormTaskData = ({ participantId, taskId, profileId, formData, step = 0, }: getCreditCardFormTaskDataProps): UpdateUserTaskBody => { const isNewMicroservice = checkNewMicroservice(); const participantInfo = { id: participantId, ...(!isNewMicroservice && { profile: { id: profileId, }, }), roleCd: { key: 'BORROWER', value: 'Заемщик', }, ...getCurrentStepData(step, formData), }; return { sendToBank: true, taskKind: 'UNITED', task: { id: taskId, ...getOfficeCode(formData), authorizedAgentId: formData?.bankEmployeeCode, ...(isNewMicroservice ? { participant: participantInfo, } : { participants: [participantInfo], }), ...getCardOptionsData(formData), ...getDeliveryData(formData), esiaAccountTypeCd: { key: formData?.esiaAccountTypeCd?.key, } as UpdateUserTaskBody['task']['esiaAccountTypeCd'], files: formData?.files, }, }; }; const getCurrentStepData = (step: number, formData: LeadFormState): Partial => { switch (step) { case 0: return {}; case 1: return getPersonalInfoData(formData); case 2: return getEmploymentData(formData); case 3: return getFamilyStatusAndIncomeData(formData); case 4: return getAdditionalInfoData(formData); case 5: return getDeliveryCreditCardData(formData); default: return {}; } };