import { triggerReview } from './triggerReview.usecase.js';
export function handleReviewRequestPush(params, deps) {
    const { reviewRequestTrackingGateway, queuePort, logger } = deps;
    const reviewRequest = reviewRequestTrackingGateway.getByNumber(params.localPath, params.reviewRequestNumber, params.platform);
    if (!reviewRequest) {
        logger.debug({ mrNumber: params.reviewRequestNumber }, 'Review request not tracked, skipping followup');
        return { action: 'skipped', reason: 'review-request-not-tracked' };
    }
    if (reviewRequest.state !== 'pending-fix') {
        logger.debug({ mrNumber: params.reviewRequestNumber, state: reviewRequest.state }, 'Review request not in pending-fix state');
        return { action: 'skipped', reason: 'not-pending-fix' };
    }
    if (reviewRequest.openThreads === 0) {
        logger.debug({ mrNumber: params.reviewRequestNumber }, 'No open threads, skipping followup');
        return { action: 'skipped', reason: 'no-open-threads' };
    }
    const jobId = queuePort.createJobId(`${params.platform}-followup`, params.projectPath, params.reviewRequestNumber);
    if (queuePort.hasActiveJob(jobId)) {
        logger.debug({ jobId }, 'Review already in progress');
        return { action: 'skipped', reason: 'review-in-progress' };
    }
    const triggerParams = {
        platform: params.platform,
        projectPath: params.projectPath,
        localPath: params.localPath,
        reviewRequestNumber: params.reviewRequestNumber,
        title: reviewRequest.title,
        sourceBranch: reviewRequest.sourceBranch,
        targetBranch: reviewRequest.targetBranch,
        mrUrl: params.mrUrl,
        skill: params.skill,
        jobType: 'followup',
    };
    const result = triggerReview(triggerParams, {
        queuePort,
        reviewRequestTrackingGateway,
        logger,
    });
    if (result.status === 'success') {
        logger.info({ jobId: result.jobId, mrNumber: params.reviewRequestNumber }, 'Followup review triggered');
        return { action: 'followup-triggered', jobId: result.jobId };
    }
    return { action: 'skipped', reason: 'review-in-progress' };
}
//# sourceMappingURL=handleReviewRequestPush.usecase.js.map