import { basename } from 'node:path';
export class AddRepositoryFromDashboardUseCase {
    deps;
    constructor(deps) {
        this.deps = deps;
    }
    execute(input) {
        if (!this.deps.isDirectory(input.localPath)) {
            return { status: 'not-a-directory' };
        }
        const name = basename(input.localPath);
        const entry = { name, localPath: input.localPath, enabled: true };
        try {
            const result = this.deps.addRepositoriesToConfig.execute({
                configPath: this.deps.configPath,
                newRepositories: [entry],
            });
            if (result.skipped.length > 0) {
                return { status: 'duplicate' };
            }
        }
        catch {
            return { status: 'write-failed' };
        }
        const enriched = this.deps.enrichSingleRepository(entry);
        this.deps.repositories.push(enriched);
        return { status: 'ok', repositories: this.deps.repositories };
    }
}
//# sourceMappingURL=addRepositoryFromDashboard.usecase.js.map