/**
 * Rule: evolve-reflects-in-list
 *
 * For every model with a lifecycle, seed an entity in the initial
 * state, transition it to the next state via backend PATCH, and
 * assert the list view reflects the new state. This exercises the
 * lifecycle mutation path through the same state-sync contract as
 * create/delete.
 *
 * Uses the first → second state transition from the lifecycle flow.
 * If the lifecycle has fewer than two states, the rule produces no
 * test case for that model.
 *
 * One TestCase per (seedable, lifecycled) model. For poll-app: Poll
 * has a lifecycle with states draft → open → closed, so a single
 * test covers the draft → open transition.
 */
import { pickDisplayAttribute, buildSeedData, getLifecycleStates } from './_shared.js';
export const RULE_ID = 'evolve-reflects-in-list';
export const evolveReflectsInList = (spec) => {
    const cases = [];
    for (const model of spec.models) {
        const states = getLifecycleStates(model);
        if (!states || states.length < 2)
            continue;
        const display = pickDisplayAttribute(model);
        if (!display)
            continue;
        const marker = `ct-evolve-${model.name}`;
        const seedData = buildSeedData(model, marker);
        if (!seedData)
            continue;
        const displayValue = seedData[display.name];
        if (typeof displayValue !== 'string')
            continue;
        const [fromState, toState] = states;
        cases.push({
            ruleId: RULE_ID,
            specElement: `${model.name} ${fromState}→${toState}`,
            name: `[${RULE_ID}] evolving a ${model.name} from '${fromState}' to '${toState}' updates the list view`,
            steps: [
                { action: 'bootRuntime' },
                { action: 'navigateToModel', modelName: model.name },
                {
                    action: 'createEntity',
                    modelName: model.name,
                    data: seedData,
                    bindAs: '{ id, data: created }',
                    uniqueField: display.name,
                },
                {
                    action: 'expectEntityInList',
                    modelName: model.name,
                    displayExpr: `String(created[${JSON.stringify(display.name)}])`,
                },
                { action: 'evolveEntity', modelName: model.name, idExpr: 'id', targetState: toState },
                { action: 'expectLifecycleState', modelName: model.name, stateName: toState },
            ],
        });
    }
    return cases;
};
//# sourceMappingURL=evolve-reflects-in-list.js.map