import { RetentionPolicy } from '../../../../modules/data-lifecycle/entities/cleanup/retentionPolicy.valueObject.js';
export async function cleanupExpiredReviews(projectPath, retentionDays, dependencies, now = new Date()) {
    const { reviewFileGateway, reviewLogFileGateway } = dependencies;
    const retentionPolicy = RetentionPolicy.create(retentionDays);
    const deletedReviewFiles = await deleteExpiredReviewFiles(projectPath, retentionPolicy, reviewFileGateway, now);
    const deletedLogFiles = await deleteExpiredLogFiles(projectPath, retentionPolicy, reviewLogFileGateway, now);
    return {
        deletedReviewFiles,
        deletedLogFiles,
        totalDeletedCount: deletedReviewFiles.length + deletedLogFiles.length,
    };
}
async function deleteExpiredReviewFiles(projectPath, retentionPolicy, reviewFileGateway, now) {
    const reviews = await reviewFileGateway.listReviews(projectPath);
    const deletedFiles = [];
    for (const review of reviews) {
        const fileDate = new Date(review.date);
        if (retentionPolicy.isExpired(fileDate, now)) {
            const deleted = await reviewFileGateway.deleteReview(projectPath, review.filename);
            if (deleted) {
                deletedFiles.push(review.filename);
            }
        }
    }
    return deletedFiles;
}
async function deleteExpiredLogFiles(projectPath, retentionPolicy, reviewLogFileGateway, now) {
    const logFiles = await reviewLogFileGateway.listLogFiles(projectPath);
    const deletedFiles = [];
    for (const logFile of logFiles) {
        const fileDate = new Date(logFile.mtime);
        if (retentionPolicy.isExpired(fileDate, now)) {
            const deleted = await reviewLogFileGateway.deleteLogFile(projectPath, logFile.filename);
            if (deleted) {
                deletedFiles.push(logFile.filename);
            }
        }
    }
    return deletedFiles;
}
//# sourceMappingURL=cleanupExpiredReviews.usecase.js.map