/**
 * Rule: lifecycle-state-visible-in-detail
 *
 * For every model with a lifecycle, the detail view should surface
 * the lifecycle's state names. v1 checks the *first* (initial)
 * state — typically what a fresh instance shows — because that's
 * the one guaranteed to exist without creating data.
 *
 * Lifecycle shape in the spec:
 *   lifecycles:
 *     status:
 *       flow: draft -> open -> closed
 *
 * We parse the `flow` string to extract states. If the model uses a
 * different shape (e.g. an explicit `states: [...]`), the parser
 * should normalize both into the same structure.
 *
 * One TestCase per (model, lifecycle) pair — not per state, since
 * testing every state requires creating instances and evolving them,
 * which belongs to the state-sync rules.
 */
export const RULE_ID = 'lifecycle-state-visible-in-detail';
function extractInitialState(lifecycleDef) {
    if (!lifecycleDef)
        return null;
    // Form 1: { flow: 'draft -> open -> closed' }
    if (typeof lifecycleDef.flow === 'string') {
        const first = lifecycleDef.flow.split('->')[0]?.trim();
        if (first)
            return first;
    }
    // Form 2: { states: ['draft', 'open', 'closed'] }
    if (Array.isArray(lifecycleDef.states) && lifecycleDef.states.length > 0) {
        const first = lifecycleDef.states[0];
        return typeof first === 'string' ? first : first?.name || null;
    }
    // Form 3: { initial: 'draft', states: {...} }
    if (typeof lifecycleDef.initial === 'string')
        return lifecycleDef.initial;
    return null;
}
export const lifecycleStateVisibleInDetail = (spec) => {
    const cases = [];
    for (const model of spec.models) {
        const lifecycles = model.lifecycles;
        if (!lifecycles)
            continue;
        for (const [lcName, lcDef] of Object.entries(lifecycles)) {
            const initial = extractInitialState(lcDef);
            if (!initial)
                continue;
            cases.push({
                ruleId: RULE_ID,
                specElement: `${model.name}.${lcName}`,
                name: `[${RULE_ID}] ${model.name}.${lcName} initial state '${initial}' visible`,
                steps: [
                    { action: 'bootRuntime' },
                    { action: 'navigateToModelDetail', modelName: model.name },
                    { action: 'expectLifecycleState', modelName: model.name, stateName: initial },
                ],
            });
        }
    }
    return cases;
};
//# sourceMappingURL=lifecycle-state-visible-in-detail.js.map