import { Service } from 'typedi'; import { BindDataType, } from '@sky-distribution/policy-service-interfaces/lib/core/SubmissionForm.type'; import { SubmissionFormWithId } from './CreateSubmissionModel.type'; import { SubmissionQuoteRequest } from '../../api/rpc/types/Rpc.Quote.type'; @Service() export class QuoteSubmissionModel { constructor(private readonly input: SubmissionQuoteRequest) {} private setBindData(): BindDataType | undefined { const submittedBindDataFields = { ...(this.input.selectedPaymentPlan ? { selectedPaymentPlan: this.input.selectedPaymentPlan } : {}), ...(this.input.chosenQuote ? { chosenQuote: this.input.chosenQuote } : {}), ...(this.input.branchName_SKY ? { branchName_SKY: this.input.branchName_SKY } : {}), }; return Object.keys(submittedBindDataFields).length || this.input.submissionForm?.bindData ? { ...this.input.submissionForm?.bindData, ...submittedBindDataFields } : undefined; } toJson(): SubmissionFormWithId { return { submissionForm: { ...this.input.submissionForm, bindData: this.setBindData(), }, id: this.input.correlationId, }; } }