<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Category;
use App\Services\DummyDataService;
use Illuminate\Support\Str;

class CategorySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $books = DummyDataService::getAllBooks();
        $recommendations = DummyDataService::getRekomendasiPembelajaran();

        $categories = collect($books)->pluck('kategori')
            ->merge(collect($recommendations)->pluck('kategori'))
            ->unique()
            ->filter();

        foreach ($categories as $name) {
            Category::updateOrCreate(
                ['slug' => Str::slug($name)],
                ['name' => $name]
            );
        }
    }
}
