<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Faker\Generator as Faker;
use App\Models\Category;
use App\Models\Book;

class BooksSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run(Faker $faker) {
        $categories = Category::pluck('id');
        
        for ($i = 0; $i < 10; $i++) {
            Book::create([
                'isbn' => $faker->unique()->randomElement([$faker->isbn10(), $faker->isbn13()]),
                'title' => 'Book' . $i,
                'authors' => 'Author' . $i,
                'year' => $faker->year(),
                'editorial' => 'Editorial' . $i,
                'document' => null,
                'category_id' => $categories[$i%count($categories)]
            ]);
        }
        
        for ($i = 0; $i < 10; $i++) {
            Book::create([
                'isbn' => $faker->unique()->randomElement([$faker->isbn10(), $faker->isbn13()]),
                'title' => 'Book' . $i,
                'authors' => 'Author' . $i,
                'year' => $faker->year(),
                'editorial' => 'Editorial' . $i,
                'document' => '/data/documents/default_book.pdf',
                'category_id' => $categories[$i%count($categories)]
            ]);
        }
    }
}
