import fs from 'node:fs';
import path from 'node:path';
import { z } from 'zod';
import Config from './config.js';
import constants from './constants.js';
export default class RunSpecConfig extends Config {
    static schema = z.object({
        command: z.array(z.string()).optional(),
        egress: z.boolean().optional(),
        env: z.record(z.string().min(1, "Environment variable name cannot be empty"), z.string()).optional(),
        image: z.string(),
        scriptDir: z.string().optional(),
        workDir: z.string().optional()
    }).strict();
    schema = RunSpecConfig.schema;
    name;
    constructor(srcPath, name = constants.DEFAULT_RUNSPEC_NAME) {
        super(path.join(srcPath, `config/run/${name}.yml`));
        this.name = name;
    }
    static getAll(srcPath) {
        const configDir = path.resolve(path.join(srcPath, 'config/run'));
        const configFiles = fs.readdirSync(configDir).filter(file => path.extname(file) === '.yml');
        if (!configFiles.includes(`${constants.DEFAULT_RUNSPEC_NAME}.yml`)) {
            throw new Error(`No default runSpec found in config/run/${constants.DEFAULT_RUNSPEC_NAME}.yml.`);
        }
        return configFiles.map(configFile => new RunSpecConfig(srcPath, configFile.split('.')[0]));
    }
    getName() {
        return this.name;
    }
}
