import { isTimeoutContinuationPartId } from './team-leader-continuation-ids.js';
function assertNonEmptyString(value, fieldName, index) {
    if (typeof value !== 'string' || value.trim().length === 0) {
        throw new Error(`Part[${index}] "${fieldName}" must be a non-empty string`);
    }
    return value;
}
export function parsePartDefinitionEntry(entry, index) {
    if (typeof entry !== 'object' || entry == null || Array.isArray(entry)) {
        throw new Error(`Part[${index}] must be an object`);
    }
    const raw = entry;
    if ('timeout_ms' in raw) {
        throw new Error(`Part[${index}] "timeout_ms" is not supported; use team_leader.timeout_ms instead`);
    }
    const id = assertNonEmptyString(raw.id, 'id', index);
    if (isTimeoutContinuationPartId(id)) {
        throw new Error(`Part[${index}] "id" uses reserved timeout continuation prefix: ${id}`);
    }
    const title = assertNonEmptyString(raw.title, 'title', index);
    const instruction = assertNonEmptyString(raw.instruction, 'instruction', index);
    return {
        id,
        title,
        instruction,
    };
}
export function ensureUniquePartIds(parts) {
    const ids = new Set();
    for (const part of parts) {
        if (ids.has(part.id)) {
            throw new Error(`Duplicate part id: ${part.id}`);
        }
        ids.add(part.id);
    }
}
//# sourceMappingURL=part-definition-validator.js.map