/** * 行业分区五类必备内容类别(Req 14.1, 14.4)。 * * 合法行业分区须同时具备以下全部五类内容;缺任一类即视为不完备,拒绝创建。 */ import type { IndustryPartition } from '../domain/knowledge.js'; /** * 行业分区内容类别标识(面向用户的可读名称,用于校验错误中指明缺失类别)。 */ export type PartitionCategory = | 'Indicator' | '权重模板' | 'Redline' | '典型案例' | '追问话术'; /** 五类必备内容类别的全部取值(顺序对齐 Req 14.1 表述)。 */ export const PARTITION_CATEGORY_VALUES = [ 'Indicator', '权重模板', 'Redline', '典型案例', '追问话术', ] as const satisfies readonly PartitionCategory[]; /** * 各类别到其在 {@link IndustryPartition} 中承载字段的映射。 * * 校验时据此读取对应集合:集合为空(或缺失)即认定该类别缺失。 */ const CATEGORY_FIELDS: ReadonlyArray<{ readonly category: PartitionCategory; readonly field: keyof IndustryPartition; }> = [ { category: 'Indicator', field: 'indicators' }, { category: '权重模板', field: 'weightTemplates' }, { category: 'Redline', field: 'redlines' }, { category: '典型案例', field: 'cases' }, { category: '追问话术', field: 'askPrompts' }, ]; /** * 找出某行业分区缺失的内容类别(Req 14.1, 14.4)。 * * 判定规则:对应字段不是数组、或为空数组,即视为该类别缺失。 * * @returns 缺失类别列表(顺序对齐 {@link PARTITION_CATEGORY_VALUES});为空表示五类齐备。 */ export function findMissingCategories( partition: IndustryPartition, ): PartitionCategory[] { const missing: PartitionCategory[] = []; for (const { category, field } of CATEGORY_FIELDS) { const value = partition[field]; if (!Array.isArray(value) || value.length === 0) { missing.push(category); } } return missing; } /** * 判断某行业分区是否五类内容齐备(不缺任一类)。 */ export function isPartitionComplete(partition: IndustryPartition): boolean { return findMissingCategories(partition).length === 0; }