export class SyncThreadsUseCase {
    trackingGateway;
    threadFetchGateway;
    constructor(trackingGateway, threadFetchGateway) {
        this.trackingGateway = trackingGateway;
        this.threadFetchGateway = threadFetchGateway;
    }
    execute(input) {
        const mr = this.trackingGateway.getById(input.projectPath, input.mrId);
        if (!mr)
            return null;
        const threads = this.threadFetchGateway.fetchThreads(mr.project, mr.mrNumber);
        const open = threads.filter((t) => t.status === 'open').length;
        const total = threads.length;
        const hasOpenThreads = open > 0;
        const wasPendingFix = mr.state === 'pending-fix';
        this.trackingGateway.update(input.projectPath, input.mrId, {
            openThreads: open,
            totalThreads: total,
            ...(hasOpenThreads ? { state: 'pending-fix' } :
                wasPendingFix ? { state: 'pending-approval' } : {}),
        });
        return this.trackingGateway.getById(input.projectPath, input.mrId) ?? null;
    }
}
//# sourceMappingURL=syncThreads.usecase.js.map