const { sequelize, Book, Review } = require('../models');

async function resetReviews() {
    try {
        console.log("Starting review reset...");

        // 1. Delete all reviews
        console.log("Deleting all reviews...");
        await Review.destroy({
            where: {},
            truncate: true // Reset auto-increment ID
        });
        console.log("All reviews deleted.");

        // 2. Reset all book ratings to 0
        console.log("Resetting all book ratings to 0...");
        await Book.update(
            { rating: 0 },
            { where: {} } // Apply to all books
        );
        console.log("All book ratings reset to 0.");

        console.log("SUCCESS: Database is now clean of reviews and ratings.");
    } catch (error) {
        console.error("Error resetting reviews:", error);
    } finally {
        await sequelize.close();
    }
}

resetReviews();
