import { optionalString, requireStringList } from '../args.js';
import { createContext } from '../context.js';
import { CliError } from '../errors.js';
import { writeOutput } from '../output.js';
import { withMeta } from './_meta.js';
export function runTaggedListMixed(args) {
    const tags = requireStringList(args, 'tags');
    const filterRaw = optionalString(args, 'filter') ?? 'or';
    if (filterRaw !== 'and' && filterRaw !== 'or') {
        throw new CliError('INVALID_ARGS', `--filter must be 'and' or 'or', got '${filterRaw}'`);
    }
    const ctx = createContext(args);
    try {
        const entities = ctx.reader.findByTag({ tags, filter: filterRaw });
        const grouped = {
            endpoints: [],
            dtos: [],
            'database-tables': [],
            'ui-views': [],
            acs: [],
        };
        const bucket = {
            endpoint: 'endpoints',
            dto: 'dtos',
            'database-table': 'database-tables',
            'ui-view': 'ui-views',
            ac: 'acs',
        };
        for (const entity of entities) {
            const result = ctx.registry.serializeEntity(entity.type, 'tagged_list_item', entity, ctx.reader);
            grouped[bucket[entity.type]].push(withMeta(result));
        }
        writeOutput({ ...grouped, query: { tags, filter: filterRaw } }, args);
    }
    finally {
        ctx.close();
    }
}
//# sourceMappingURL=tagged-list-mixed.js.map