import type { Argv } from 'yargs';
import { types } from './types';
import { list, options as listOptions } from './list';
import { invoke, invokeOptions } from './invoke';
import { CONFIG_DEFAULT } from '@plastichub/osr-commons';
import { logger } from '../';

export const commands = (yargs: Argv) => {
    return yargs
        .command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)
        .command('list', 'List all available tools and their descriptions', listOptions, list)
        .command('invoke', 'Invoke a specific tool function', invokeOptions, invoke)
        .option('env_key', {
            type: 'string',
            description: 'Environment configuration key'
        })
        .middleware([(argv) => {
            const config = CONFIG_DEFAULT(argv.env_key) as any;
            if (!config) {
                logger.warn('No config found!');
                return;
            }
            return config;
        }])
        .strict()
        .help();
};