import type { Attachment } from './attachments.ts'; import type { Demand, Fields } from './demand.ts'; export type ReviewPerson = { userId: string; username: string; displayName: string }; export type ReviewProposal = { version: number; scope: string; outOfScope: string; developer: ReviewPerson; submittedAt: string; businessFields: Fields; businessAttachments?: Attachment[]; invalidated?: { time: string; reason: string }; decision?: { result: 'confirmed' | 'changes_requested'; actor: ReviewPerson; time: string; comment: string }; }; export type DemandReview = { developer: ReviewPerson; proposals: ReviewProposal[] }; export type DemandAccess = { business: boolean; developer: boolean; canTakeOverDevelopment?: boolean }; export function currentProposal(d: Demand): ReviewProposal | undefined { return d.review?.proposals.at(-1); } export function reviewStage(d: Demand): string { if (!d.reviewReady) return '资料待补充'; if (!d.review) return '待开发提出方案'; const proposal = currentProposal(d); if (!proposal || proposal.invalidated) return '待开发提出方案'; if (proposal.decision?.result === 'confirmed') return '方案已确认'; if (proposal.decision?.result === 'changes_requested') return '待开发修改方案'; return '待业务确认方案'; } export function invalidateProposal(d: Demand, time: string, reason: string): void { const proposal = currentProposal(d); if (proposal && !proposal.invalidated) proposal.invalidated = { time, reason }; }