import { success, failure, appError, type Result, type AppError } from '@relink/shared'; export type ContractType = 'ACQUISITION' | 'DEMOLITION' | 'INTERIOR'; export interface CreateContractInput { readonly matchRequestStatus: string; readonly contractType: ContractType; readonly templateCode: string; readonly policyVersionId: string; } export interface ContractDraft { readonly contractType: ContractType; readonly status: 'DRAFT'; readonly templateCode: string; readonly policyVersionId: string; } export function createContract( input: CreateContractInput, ): Result { // U021: 수락된 매칭만 계약 생성 가능 if (input.matchRequestStatus !== 'ACCEPTED') { return failure( appError('MATCH_NOT_ACCEPTED', '수락된 매칭 요청만 계약을 생성할 수 있습니다.', { matchRequestStatus: input.matchRequestStatus, }), ); } // U022: 템플릿 코드 필수 if (!input.templateCode.trim()) { return failure( appError('VALIDATION_ERROR', '계약 템플릿 코드는 필수입니다.', { field: 'templateCode' }), ); } // U022: 정책 버전 필수 if (!input.policyVersionId.trim()) { return failure( appError('VALIDATION_ERROR', '정책 버전은 필수입니다.', { field: 'policyVersionId' }), ); } return success({ contractType: input.contractType, status: 'DRAFT' as const, templateCode: input.templateCode, policyVersionId: input.policyVersionId, }); }