import { color, hux } from '@heroku/heroku-cli-util';
import { Command, flags as Flags } from '@heroku-cli/command';
import { getGeneration } from '../../lib/apps/generation.js';
import { BuildpackCommand } from '../../lib/buildpacks/buildpacks.js';
export default class Index extends Command {
    static description = 'list the buildpacks on an app';
    static flags = {
        app: Flags.app({ required: true }),
        remote: Flags.remote(),
    };
    async run() {
        const { flags } = await this.parse(Index);
        const buildpacksCommand = new BuildpackCommand(this.heroku);
        const { body: app } = await this.heroku.get(`/apps/${flags.app}`, {
            headers: {
                Accept: 'application/vnd.heroku+json; version=3.sdk',
            },
        });
        const isFirApp = getGeneration(app) === 'fir';
        const buildpacks = await buildpacksCommand.fetch(flags.app, isFirApp);
        if (buildpacks.length === 0) {
            this.log(`${color.app(flags.app)} has no Buildpacks.`);
        }
        else {
            const pluralizedBuildpacks = buildpacks.length > 1 ? 'Buildpacks' : 'Buildpack';
            let header = `${color.app(flags.app)}`;
            if (isFirApp) {
                header += ` Cloud Native ${pluralizedBuildpacks} (from the latest release's OCI image)`;
            }
            else {
                header += ` Classic ${pluralizedBuildpacks} (from the Heroku Buildpack Registry)`;
            }
            hux.styledHeader(header);
            buildpacksCommand.display(buildpacks, '');
        }
    }
}
