"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const client_1 = require("@prisma/client");
const bcrypt = __importStar(require("bcryptjs"));
const prisma = new client_1.PrismaClient();
async function main() {
    console.log('🌱 Starting database seed for Indian Books Worldwide...');
    // 1. Clean existing data
    await prisma.review.deleteMany({});
    await prisma.wishlist.deleteMany({});
    await prisma.cartItem.deleteMany({});
    await prisma.cart.deleteMany({});
    await prisma.paymentDetails.deleteMany({});
    await prisma.orderItem.deleteMany({});
    await prisma.order.deleteMany({});
    await prisma.inventory.deleteMany({});
    await prisma.bookImage.deleteMany({});
    await prisma.bookAuthor.deleteMany({});
    await prisma.bookCategory.deleteMany({});
    await prisma.book.deleteMany({});
    await prisma.author.deleteMany({});
    await prisma.category.deleteMany({});
    await prisma.address.deleteMany({});
    await prisma.refreshToken.deleteMany({});
    await prisma.user.deleteMany({});
    console.log('🧹 Cleaned existing tables.');
    // 2. Hash default password
    const hashedPassword = await bcrypt.hash('Password@123', 10);
    // 3. Seed Users
    const adminUser = await prisma.user.create({
        data: {
            email: 'admin@indianbooksworldwide.com',
            password: hashedPassword,
            fullName: 'Vedic Admin',
            phone: '+919876543210',
            role: client_1.Role.ADMIN,
            avatarUrl: 'https://images.unsplash.com/photo-1534528741775-53994a69daeb',
        },
    });
    const sellerUser = await prisma.user.create({
        data: {
            email: 'seller@indianbooksworldwide.com',
            password: hashedPassword,
            fullName: 'Heritage Book Distributors',
            phone: '+919876543211',
            role: client_1.Role.SELLER,
            avatarUrl: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d',
        },
    });
    const customerUser = await prisma.user.create({
        data: {
            email: 'customer@indianbooksworldwide.com',
            password: hashedPassword,
            fullName: 'Aarav Sharma',
            phone: '+919876543212',
            role: client_1.Role.CUSTOMER,
            avatarUrl: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e',
            addresses: {
                create: [
                    {
                        fullName: 'Aarav Sharma',
                        phone: '+919876543212',
                        street: '42 MG Road, Connaught Place',
                        city: 'New Delhi',
                        state: 'Delhi',
                        postalCode: '110001',
                        country: 'India',
                        isDefault: true,
                    },
                ],
            },
        },
    });
    console.log('👤 Created default users (Admin, Seller, Customer).');
    // 4. Seed Authors
    const tagore = await prisma.author.create({
        data: {
            name: 'Rabindranath Tagore',
            slug: 'rabindranath-tagore',
            bio: 'Nobel Laureate Bengali polymath who reshaped Bengali literature and Indian art with Contextual Modernism.',
            photoUrl: 'https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c',
            birthDate: '1861-05-07',
        },
    });
    const rkNarayan = await prisma.author.create({
        data: {
            name: 'R.K. Narayan',
            slug: 'rk-narayan',
            bio: 'One of the finest early Indian writers in English, best known for his work set in the fictional South Indian town of Malgudi.',
            photoUrl: 'https://images.unsplash.com/photo-1492562080023-ab3db95bfbce',
            birthDate: '1906-10-10',
        },
    });
    const ruskinBond = await prisma.author.create({
        data: {
            name: 'Ruskin Bond',
            slug: 'ruskin-bond',
            bio: 'Iconic Indian author of British descent, renowned for stories depicting life in the Himalayan foothills of Mussoorie and Dehradun.',
            photoUrl: 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde',
            birthDate: '1934-05-19',
        },
    });
    const amishTripathi = await prisma.author.create({
        data: {
            name: 'Amish Tripathi',
            slug: 'amish-tripathi',
            bio: 'Bestselling author celebrated for his epic mythological fiction series including Shiva Trilogy and Ram Chandra Series.',
            photoUrl: 'https://images.unsplash.com/photo-1522075469751-3a6694fb2f61',
            birthDate: '1974-10-18',
        },
    });
    const arundhatiRoy = await prisma.author.create({
        data: {
            name: 'Arundhati Roy',
            slug: 'arundhati-roy',
            bio: 'Booker Prize-winning author and political activist best known for The God of Small Things.',
            photoUrl: 'https://images.unsplash.com/photo-1573496359142-b8d87734a5a2',
            birthDate: '1961-11-24',
        },
    });
    console.log('✍️ Seeded iconic Indian authors.');
    // 5. Seed Categories
    const literature = await prisma.category.create({
        data: {
            name: 'Literature',
            slug: 'literature',
            description: 'Classic and modern Indian literary masterpieces.',
        },
    });
    const history = await prisma.category.create({
        data: {
            name: 'History',
            slug: 'history',
            description: 'Comprehensive historical accounts, ancient chronicles, and modern history of India.',
        },
    });
    const philosophy = await prisma.category.create({
        data: {
            name: 'Philosophy',
            slug: 'philosophy',
            description: 'Indian philosophical traditions, Upanishads, and spiritual discourse.',
        },
    });
    const vedicSciences = await prisma.category.create({
        data: {
            name: 'Vedic Sciences',
            slug: 'vedic-sciences',
            description: 'Ayurveda, Vedic Astrology (Jyotish), Yoga, Vastu Shastra, and Sanskrit texts.',
        },
    });
    const fiction = await prisma.category.create({
        data: {
            name: 'Fiction',
            slug: 'fiction',
            description: 'Captivating Indian novels, mythological re-imaginings, and short story collections.',
        },
    });
    console.log('📚 Seeded book categories.');
    // 6. Seed Books
    const booksData = [
        {
            title: 'Gitanjali (Song Offerings)',
            slug: 'gitanjali-song-offerings',
            isbn: '9788171670277',
            description: 'A profound collection of 103 prose poems translated into English by Rabindranath Tagore himself, which won him the Nobel Prize in Literature in 1913.',
            price: 299.0,
            discountPrice: 249.0,
            stock: 50,
            format: client_1.BookFormat.PAPERBACK,
            language: 'English',
            publisher: 'Rupa Publications',
            publicationDate: new Date('1912-11-01'),
            pageCount: 160,
            coverImage: 'https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c',
            isFeatured: true,
            isBestseller: true,
            sellerId: sellerUser.id,
            authorId: tagore.id,
            categoryId: literature.id,
        },
        {
            title: 'Malgudi Days',
            slug: 'malgudi-days',
            isbn: '9780140188981',
            description: 'An enduring collection of short stories depicting the poignant, humorous, and timeless life in the enchanted South Indian town of Malgudi.',
            price: 399.0,
            discountPrice: 329.0,
            stock: 75,
            format: client_1.BookFormat.PAPERBACK,
            language: 'English',
            publisher: 'Penguin Classics',
            publicationDate: new Date('1943-01-01'),
            pageCount: 256,
            coverImage: 'https://images.unsplash.com/photo-1512820790803-83ca734da794',
            isFeatured: true,
            isBestseller: true,
            sellerId: sellerUser.id,
            authorId: rkNarayan.id,
            categoryId: fiction.id,
        },
        {
            title: 'The Immortals of Meluha (Shiva Trilogy Book 1)',
            slug: 'the-immortals-of-meluha',
            isbn: '9789380658742',
            description: '1900 BC. In what modern Indians mistakenly call the Indus Valley Civilisation, Shiva arrives to fulfill an ancient prophecy and protect Meluha.',
            price: 450.0,
            discountPrice: 375.0,
            stock: 120,
            format: client_1.BookFormat.PAPERBACK,
            language: 'English',
            publisher: 'Westland Press',
            publicationDate: new Date('2010-02-01'),
            pageCount: 436,
            coverImage: 'https://images.unsplash.com/photo-1532012197267-da84d127e765',
            isFeatured: true,
            isBestseller: true,
            sellerId: sellerUser.id,
            authorId: amishTripathi.id,
            categoryId: fiction.id,
        },
        {
            title: 'The God of Small Things',
            slug: 'the-god-of-small-things',
            isbn: '9780679457312',
            description: 'The story of fraternal twins Estha and Rahel in Kerala whose lives are destroyed by the Love Laws that lay down who should be loved, and how much.',
            price: 499.0,
            discountPrice: 399.0,
            stock: 40,
            format: client_1.BookFormat.PAPERBACK,
            language: 'English',
            publisher: 'Random House',
            publicationDate: new Date('1997-04-04'),
            pageCount: 340,
            coverImage: 'https://images.unsplash.com/photo-1497633762265-9d179a990aa6',
            isFeatured: false,
            isBestseller: true,
            sellerId: sellerUser.id,
            authorId: arundhatiRoy.id,
            categoryId: literature.id,
        },
        {
            title: 'The Room on the Roof',
            slug: 'the-room-on-the-roof',
            isbn: '9780140237931',
            description: 'Ruskin Bond\'s classic debut novel written when he was seventeen, capturing the bittersweet beauty of youth in Dehradun.',
            price: 250.0,
            discountPrice: 199.0,
            stock: 60,
            format: client_1.BookFormat.PAPERBACK,
            language: 'English',
            publisher: 'Penguin India',
            publicationDate: new Date('1956-01-01'),
            pageCount: 192,
            coverImage: 'https://images.unsplash.com/photo-1476275466078-4007374efbbe',
            isFeatured: true,
            isBestseller: false,
            sellerId: sellerUser.id,
            authorId: ruskinBond.id,
            categoryId: fiction.id,
        },
        {
            title: 'The Bhagavad Gita: Essence of Ancient Wisdom',
            slug: 'the-bhagavad-gita-essence',
            isbn: '9788178232980',
            description: 'A clear commentary and translation of the 700 verses of the Bhagavad Gita detailing Karma Yoga, Jnana Yoga, and Bhakti Yoga.',
            price: 599.0,
            discountPrice: 499.0,
            stock: 80,
            format: client_1.BookFormat.HARDCOVER,
            language: 'Sanskrit & English',
            publisher: 'Vedic Heritage Press',
            publicationDate: new Date('2020-08-15'),
            pageCount: 520,
            coverImage: 'https://images.unsplash.com/photo-1506880018603-83d5b814b5a6',
            isFeatured: true,
            isBestseller: true,
            sellerId: sellerUser.id,
            authorId: tagore.id,
            categoryId: philosophy.id,
        },
        {
            title: 'Ayurvedic Healing: A Comprehensive Guide',
            slug: 'ayurvedic-healing-comprehensive-guide',
            isbn: '9788120811568',
            description: 'A master treatise on classical Indian medicinal science, herbal treatments, and dosha balance for holistic health.',
            price: 750.0,
            discountPrice: 620.0,
            stock: 35,
            format: client_1.BookFormat.PAPERBACK,
            language: 'English',
            publisher: 'Motilal Banarsidass',
            publicationDate: new Date('2018-05-10'),
            pageCount: 410,
            coverImage: 'https://images.unsplash.com/photo-1544717305-2782549b5136',
            isFeatured: false,
            isBestseller: false,
            sellerId: sellerUser.id,
            authorId: ruskinBond.id,
            categoryId: vedicSciences.id,
        },
    ];
    for (const b of booksData) {
        const { authorId, categoryId, ...bookInfo } = b;
        const createdBook = await prisma.book.create({
            data: {
                ...bookInfo,
                authors: {
                    create: [
                        {
                            authorId: authorId,
                            role: 'Primary Author',
                        },
                    ],
                },
                categories: {
                    create: [
                        {
                            categoryId: categoryId,
                        },
                    ],
                },
                images: {
                    create: [
                        {
                            url: bookInfo.coverImage,
                            altText: bookInfo.title,
                            isPrimary: true,
                        },
                    ],
                },
                inventories: {
                    create: [
                        {
                            sellerId: sellerUser.id,
                            quantity: bookInfo.stock,
                            sku: `SKU-${bookInfo.isbn}`,
                            location: 'Warehouse Delhi-1',
                        },
                    ],
                },
            },
        });
        // Create a sample review for featured books
        if (b.isFeatured) {
            await prisma.review.create({
                data: {
                    bookId: createdBook.id,
                    userId: customerUser.id,
                    rating: 5,
                    title: 'Absolute Masterpiece!',
                    comment: 'Essential reading for everyone interested in Indian literature and profound philosophical depths.',
                },
            });
            // Update avg rating
            await prisma.book.update({
                where: { id: createdBook.id },
                data: {
                    averageRating: 5.0,
                    reviewCount: 1,
                },
            });
        }
    }
    console.log('📖 Seeded 7 featured Indian books with inventory & images.');
    console.log('✅ Seeding completed successfully!');
}
main()
    .catch((e) => {
    console.error('❌ Seeding error:', e);
    process.exit(1);
})
    .finally(async () => {
    await prisma.$disconnect();
});
//# sourceMappingURL=seed.js.map