import type { IUserInfo } from "@/shared/store"; import type { DesignCnstnMngDetResponseDto } from "@/entities/design-cnstn"; import { toEsntlAtchFileSaveList } from "@/widgets/pbadms-sprt"; import type { DesignCnstnRegistFormData } from "./design-cnstn-regist-schema"; import { parseTaskSeComCdFromApi } from "./design-cnstn-regist-schema"; export function mapDetailToFormData(data: DesignCnstnMngDetResponseDto): DesignCnstnRegistFormData { const detDto = data.detDto; if (!detDto) { throw new Error("상세 정보(detDto)가 없습니다."); } const bizSclList = data.bizSclList ?? []; return { designCnstnMng: { designCnstnDocNo: detDto.designCnstnDocNo, bizNm: detDto.bizNm ?? "", bizBgngYr: detDto.bizBgngYr ?? "", bizEndYr: detDto.bizEndYr ?? "", bizCn: detDto.bizCn ?? "", taskSeComCd: parseTaskSeComCdFromApi(detDto.taskSeComCd), dsgnrNm: detDto.dsgnrNm ?? "", dsgnrTelno: detDto.dsgnrTelno ?? "", dsgnrOgdpNm: detDto.dsgnrOgdpNm ?? "", dsgnrEmlAddr: detDto.dsgnrEmlAddr ?? "", aplcntNm: detDto.aplcntNm ?? "", aplcntMblTelno: detDto.aplcntMblTelno ?? "", aplcntOgdpNm: detDto.aplcntOgdpNm ?? "", aplcntEmlAddr: detDto.aplcntEmlAddr ?? "", admdstCd: detDto.admdstCd, envoSeComCd: detDto.envoSeComCd, prgrsSttsComCd: detDto.prgrsSttsComCd, atchFileGroupId: detDto.atchFileGroupId ?? "", envoSeCdNm: detDto.envoSeCdNm, taskSeCdNm: detDto.taskSeCdNm, prgrsSttsCdNm: detDto.prgrsSttsCdNm, sido: detDto.sido, gugun: detDto.gugun, regDt: detDto.regDt, rgtr: detDto.rgtr, rgtrNm: detDto.rgtrNm, mdfcnDt: detDto.mdfcnDt, }, bzScaleList: bizSclList.map((item) => ({ cnstpSeCd: item.cnstpSeCd, bscPl: item.bscPlanQty, budgetReflct: item.bgtRfltQty, thtiDsgn: item.tstmDesignQty, diff: item.tstmDesignQty - item.bgtRfltQty, })), esntlAtchFileList: toEsntlAtchFileSaveList(data.esntlFileList), privacyConsent: "Y", }; } export function getCreateDefaultValues( userInfo: IUserInfo | null, options?: { taskSeComCd?: string[]; admdstCd?: string; sido?: string; gugun?: string; }, ): DesignCnstnRegistFormData { return { designCnstnMng: { bizNm: "", bizBgngYr: "", bizEndYr: "", bizCn: "", taskSeComCd: options?.taskSeComCd ?? [], dsgnrNm: "", dsgnrTelno: "", dsgnrOgdpNm: "", dsgnrEmlAddr: "", aplcntNm: userInfo?.userName ?? "", aplcntMblTelno: userInfo?.mphn ?? "", aplcntOgdpNm: userInfo?.ogdpSeNm ?? "", aplcntEmlAddr: userInfo?.email ?? "", admdstCd: options?.admdstCd ?? "", sido: options?.sido ?? "", gugun: options?.gugun ?? "", prgrsSttsComCd: "CV", atchFileGroupId: "", }, bzScaleList: [], esntlAtchFileList: [], privacyConsent: "N", }; }