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

const seedBooks = async () => {
    try {
        await sequelize.authenticate();
        console.log('Database connected!');

        const booksData = [
            // Fiction / Novels
            {
                title: "Bumi Manusia",
                author: "Pramoedya Ananta Toer",
                price: 135000.00,
                originalPrice: 150000.00,
                stock: 45,
                rating: 4.9,
                image: "https://cdn.gramedia.com/uploads/items/9789799731234_Bumi-Manusia-Cover-Baru-2015.jpg",
                category: "Fiction",
                description: "Roman tetralogi Buru pertama yang menceritakan kegamangan Minke antara budaya Jawa dan Eropa.",
                tags: ["Sejarah", "Sastra", "Indonesia"],
                discount: 10
            },
            {
                title: "Cantik Itu Luka",
                author: "Eka Kurniawan",
                price: 125000.00,
                originalPrice: 140000.00,
                stock: 30,
                rating: 4.8,
                image: "https://cdn.gramedia.com/uploads/items/9786020312583_Cantik-Itu-Luka-Cover-Baru-2015.jpg",
                category: "Fiction",
                description: "Kisah magis dan tragis tentang Dewi Ayu dan keempat anak perempuannya di Halimunda.",
                tags: ["Sastra", "Realisme Magis"],
                discount: 11
            },
            {
                title: "Pulang",
                author: "Leila S. Chudori",
                price: 110000.00,
                originalPrice: 120000.00,
                stock: 25,
                rating: 4.7,
                image: "https://cdn.gramedia.com/uploads/items/9789799105158_pulang.jpg",
                category: "Fiction",
                description: "Kisah para eksil politik Indonesia di Paris dan keluarga mereka di Jakarta.",
                tags: ["Sejarah", "Politik", "Drama"],
                discount: 8
            },
            {
                title: "Laut Bercerita",
                author: "Leila S. Chudori",
                price: 115000.00,
                originalPrice: 130000.00,
                stock: 60,
                rating: 4.9,
                image: "https://cdn.gramedia.com/uploads/items/9786024246945_Laut-Bercerita.jpg",
                category: "Fiction",
                description: "Novel tentang persahabatan, cinta, dan pengkhianatan di masa reformasi 1998.",
                tags: ["Sejarah", "Aktivisme"],
                discount: 12
            },
            {
                title: "Gadis Kretek",
                author: "Ratih Kumala",
                price: 95000.00,
                originalPrice: 105000.00,
                stock: 40,
                rating: 4.6,
                image: "https://cdn.gramedia.com/uploads/items/9789792281414_gadis-kretek.jpg",
                category: "Fiction",
                description: "Menelusuri sejarah industri kretek di Indonesia lewat kisah cinta dan rahasia keluarga.",
                tags: ["Sejarah", "Budaya"],
                discount: 9
            },

            // Self-Help / Psychology
            {
                title: "Filosofi Teras",
                author: "Henry Manampiring",
                price: 98000.00,
                originalPrice: 110000.00,
                stock: 80,
                rating: 4.8,
                image: "https://cdn.gramedia.com/uploads/items/9786024125189_Filosofi-Teras.jpg",
                category: "Self-Help",
                description: "Filsafat Stoa untuk mental yang tangguh dan hidup yang lebih tenang masa kini.",
                tags: ["Filsafat", "Pengembangan Diri"],
                discount: 11
            },
            {
                title: "Atomic Habits",
                author: "James Clear",
                price: 108000.00,
                originalPrice: 120000.00,
                stock: 100,
                rating: 4.9,
                image: "https://cdn.gramedia.com/uploads/items/9786020633176_Atomic-Habits.jpg",
                category: "Self-Help",
                description: "Perubahan kecil yang memberikan hasil luar biasa dalam membangun kebiasaan baik.",
                tags: ["Produktivitas", "Kebiasaan"],
                discount: 10
            },
            {
                title: "Psychology of Money",
                author: "Morgan Housel",
                price: 85000.00,
                originalPrice: 95000.00,
                stock: 75,
                rating: 4.7,
                image: "https://cdn.gramedia.com/uploads/items/9786026486578_The-Psychology-of-Money.jpg",
                category: "Business",
                description: "Pelajaran abadi mengenai kekayaan, ketamakan, dan kebahagiaan.",
                tags: ["Keuangan", "Psikologi"],
                discount: 10
            },
            {
                title: "Berani Tidak Disukai",
                author: "Ichiro Kishimi",
                price: 90000.00,
                originalPrice: 100000.00,
                stock: 55,
                rating: 4.6,
                image: "https://cdn.gramedia.com/uploads/items/9786020633213_Berani-Tidak-Disukai.jpg",
                category: "Self-Help",
                description: "Fenomena dari Jepang untuk membebaskan diri, mengubah hidup, dan meraih kebahagiaan sejati.",
                tags: ["Psikologi", "Filsafat"],
                discount: 10
            },
            {
                title: "Rich Dad Poor Dad",
                author: "Robert T. Kiyosaki",
                price: 65000.00,
                originalPrice: 75000.00,
                stock: 90,
                rating: 4.8,
                image: "https://cdn.gramedia.com/uploads/items/9786020333175_Rich-Dad-Poor-Dad-Ed-Revisi-2016.jpg",
                category: "Business",
                description: "Apa yang diajarkan orang kaya pada anak-anak mereka tentang uang yang tidak diajarkan sekolah.",
                tags: ["Keuangan", "Investasi"],
                discount: 13
            },

            // Education / General
            {
                title: "Sapiens: Riwayat Singkat Umat Manusia",
                author: "Yuval Noah Harari",
                price: 155000.00,
                originalPrice: 175000.00,
                stock: 35,
                rating: 4.9,
                image: "https://cdn.gramedia.com/uploads/items/9786024248383_Sapiens-Grafis-Vol-1.jpg",
                category: "Education",
                description: "Menjelajahi cara biologi dan sejarah membentuk kita dan pemahaman kita tentang kemanusiaan.",
                tags: ["Sejarah", "Sains"],
                discount: 11
            },
            {
                title: "Dunia Sophie",
                author: "Jostein Gaarder",
                price: 130000.00,
                originalPrice: 145000.00,
                stock: 40,
                rating: 4.7,
                image: "https://cdn.gramedia.com/uploads/items/9786024410209_Duni-Sophie-Republish.jpg",
                category: "Education",
                description: "Sebuah novel filsafat yang mengajak pembaca bertualang menelusuri sejarah pemikiran manusia.",
                tags: ["Filsafat", "Novel"],
                discount: 10
            },
            {
                title: "Sebuah Seni untuk Bersikap Bodo Amat",
                author: "Mark Manson",
                price: 77000.00,
                originalPrice: 85000.00,
                stock: 120,
                rating: 4.5,
                image: "https://cdn.gramedia.com/uploads/items/9786020387604_sebuah-seni-untuk-bersikap-bodo-amat.jpg",
                category: "Self-Help",
                description: "Pendekatan yang waras demi menjalani hidup yang baik.",
                tags: ["Pengembangan Diri"],
                discount: 9
            },
            {
                title: "Madilog",
                author: "Tan Malaka",
                price: 110000.00,
                originalPrice: 125000.00,
                stock: 20,
                rating: 4.8,
                image: "https://cdn.gramedia.com/uploads/items/9789799105028_madilog-edisi-revisi-2016.jpg",
                category: "Education",
                description: "Materialisme, Dialektika, dan Logika. Karya magnum opus Tan Malaka.",
                tags: ["Filsafat", "Politik", "Sejarah"],
                discount: 12
            },
            {
                title: "Bicara Itu Ada Seninya",
                author: "Oh Su Hyang",
                price: 88000.00,
                originalPrice: 98000.00,
                stock: 65,
                rating: 4.6,
                image: "https://cdn.gramedia.com/uploads/items/9786020455587_Bicara-Itu-Ada-Seninya.jpg",
                category: "Self-Help",
                description: "Rahasia komunikasi yang efektif, negosiasi yang sukses, dan persuasi yang memikat.",
                tags: ["Komunikasi", "Pengembangan Diri"],
                discount: 10
            }
        ];

        console.log(`Adding ${booksData.length} books...`);

        // Loop and create to allow duplicates or handle errors individually if needed, 
        // or just bulkCreate. Using bulkCreate is faster.
        await Book.bulkCreate(booksData);

        console.log('Books seeded successfully!');
        process.exit(0);
    } catch (error) {
        console.error('Failed to seed books:', error);
        process.exit(1);
    }
};

seedBooks();
