import { Args, Command, Flags } from '@oclif/core';
import chalk from 'chalk';
import { discoverOrigins } from '../../origin/domain/origin-file.js';
export default class OriginList extends Command {
    static args = {
        pathspec: Args.string({
            description: 'Optional file or directory. Defaults to recursive cwd scan.',
            required: false,
        }),
    };
    static description = 'List `.origin` files emitted by `catalyst generate`.';
    static examples = [
        '<%= config.bin %> origin list',
        '<%= config.bin %> origin list backend/',
        '<%= config.bin %> origin list backend/foo.ts',
        '<%= config.bin %> origin list --json',
    ];
    static flags = {
        json: Flags.boolean({
            default: false,
            description: 'Emit machine-readable JSON instead of human text.',
        }),
    };
    async run() {
        const { args, flags } = await this.parse(OriginList);
        const origins = discoverOrigins(args.pathspec);
        if (flags.json) {
            this.log(JSON.stringify({ count: origins.length, origins }, null, 2));
            return;
        }
        if (origins.length === 0) {
            this.log('No origin files found.');
            return;
        }
        this.log(`${origins.length} origin file(s):`);
        for (const entry of origins) {
            this.log(`  ${chalk.cyan(entry.current)}  ← ${chalk.dim(entry.origin)}`);
        }
    }
}
