export class RemoveRepositoryFromConfigUseCase {
    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 index = config.repositories.findIndex((repo) => repo.localPath === input.localPath);
        if (index < 0) {
            return { removed: null, configPath: input.configPath };
        }
        const [removed] = config.repositories.splice(index, 1);
        this.deps.writeFileSync(input.configPath, JSON.stringify(config, null, 2));
        return { removed: removed ?? null, configPath: input.configPath };
    }
}
//# sourceMappingURL=removeRepositoryFromConfig.usecase.js.map