export class AddRepositoriesToConfigUseCase {
    deps;
    constructor(deps) {
        this.deps = deps;
    }
    execute(input) {
        if (!this.deps.existsSync(input.configPath)) {
            throw new Error(`Configuration file not found: ${input.configPath}\nRun 'reviewflow init' to create one.`);
        }
        const raw = this.deps.readFileSync(input.configPath, 'utf-8');
        let config;
        try {
            config = JSON.parse(raw);
        }
        catch {
            throw new Error(`Invalid JSON in configuration file: ${input.configPath}`);
        }
        const existingPaths = new Set(config.repositories.map((r) => r.localPath));
        const added = [];
        const skipped = [];
        for (const repo of input.newRepositories) {
            if (existingPaths.has(repo.localPath)) {
                skipped.push(repo);
            }
            else {
                added.push(repo);
            }
        }
        config.repositories.push(...added);
        this.deps.writeFileSync(input.configPath, JSON.stringify(config, null, 2));
        return { added, skipped, configPath: input.configPath };
    }
}
//# sourceMappingURL=addRepositoriesToConfig.usecase.js.map