const Book = require('../models/Book');

class BookRepository {
    async findAll() {
        return await Book.find();
    }

    async findById(id) {
        return await Book.findById(id);
    }

    async search(query) {
        return await Book.find({
            $or: [
                { title: { $regex: query, $options: 'i' } },
                { author: { $regex: query, $options: 'i' } }
            ]
        });
    }

    // Yangi qo'shish
    async create(data) {
        const book = new Book(data);
        return await book.save();
    }
}

module.exports = new BookRepository();