<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class BukuSeeder extends Seeder
{
    public function run(): void
    {
        $judulArray = ['Algoritma Data', 'Python Programming', 'Mobile Development', 'Web Framework', 'Database Design', 'Cloud Computing', 'Artificial Intelligence', 'Machine Learning', 'Deep Learning', 'IoT Development', 'Cybersecurity', 'Network Security', 'Software Architecture', 'Design Patterns', 'Clean Code', 'Agile Methodology', 'DevOps', 'Microservices', 'API Design', 'Testing Strategy', 'Performance Optimization'];

        $penulis = ['Prof. Adi K', 'Dr. Bambang S', 'Ir. Cahyo W', 'Drs. Dedi R', 'M.Sc. Eka P', 'Eng. Farhan A', 'Prof. Gunawan Y', 'Dr. Hendra M', 'Ir. Imam B', 'Drs. Joko S', 'M.Sc. Karina D', 'Eng. Laras H'];

        $penerbit = ['Penerbit Andi', 'Penerbit ITB', 'Gramedia', 'Erlangga', 'Kompas Media', 'Mizan', 'Elexmedia', 'PT Raja Grafindo', 'Benteng', 'Aksara', 'Kencana', 'Media Pembelajaran'];

        $nomor = ['030', '059', '045', '070', '019', '089', '100', '159', '189', '200', '250', '299', '300', '350', '399', '400', '450', '499', '500', '550', '599', '600', '650', '699', '700', '750', '799', '800', '850', '899', '900', '950', '999', '012', '035', '062', '081', '098', '120', '175', '210', '275', '310', '380', '420', '478', '520', '580', '620', '678', '720', '890', '940'];

        $kategori = DB::table('kategori')->pluck('id_kategori')->toArray();

        for ($i = 1; $i <= 110; $i++) {
            $idx = $i - 1;
            $edisi = intval(($idx / 5)) + 1;

            DB::table('buku')->insert([
                'bibid' => 'BK' . str_pad($i, 4, '0', STR_PAD_LEFT),
                'judul' => $judulArray[$idx % count($judulArray)] . ' Edisi ' . $edisi,
                'edisi' => (string)$edisi,
                'pengarang' => $penulis[$idx % count($penulis)],
                'penerbit' => $penerbit[$idx % count($penerbit)],
                'tahun_terbit' => 2018 + ($idx % 5),
                'deskripsi_fisik' => (200 + $idx * 3) . ' halaman',
                'nomor_panggil' => $nomor[$idx % count($nomor)] . ' ' . substr($penulis[$idx % count($penulis)], 0, 3),
                'konten_digital' => 0,
                'eksemplar' => 1 + ($idx % 10),
                'id_kategori' => $kategori[$idx % count($kategori)],
                'cover' => null,
                'lokasi_x' => null,
                'lokasi_y' => null,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
    }
}
