<?php

declare(strict_types=1);

namespace Database\Seeders;

use App\Models\Product;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class CategoriesTableSeeder extends Seeder
{
    public function run(): void
    {
        $adminId = User::role('admin')->first()?->id;

        $categories = [
            ['title' => 'گاو', 'slug' => 'cattle', 'model_type' => Product::class, 'order' => 1, 'page_title' => 'گاو', 'icon' => 'files/gav.jpg'],
            ['title' => 'گوسفند', 'slug' => 'sheep', 'model_type' => Product::class, 'order' => 2, 'page_title' => 'گوسفند', 'icon' => 'files/goosfand.jpg'],
            ['title' => 'بز', 'slug' => 'goat', 'model_type' => Product::class, 'order' => 3, 'page_title' => 'بز', 'icon' => null],
            ['title' => 'مرغ', 'slug' => 'poultry', 'model_type' => Product::class, 'order' => 4, 'page_title' => 'مرغ', 'icon' => 'files/booghalamoon.jpg'],
            ['title' => 'اسب', 'slug' => 'horse', 'model_type' => Product::class, 'order' => 5, 'page_title' => 'اسب', 'icon' => null],
            ['title' => 'شتر', 'slug' => 'camel', 'model_type' => Product::class, 'order' => 6, 'page_title' => 'شتر', 'icon' => 'files/shotor.jpg'],
            ['title' => 'زنبور عسل', 'slug' => 'beekeeping', 'model_type' => Product::class, 'order' => 7, 'page_title' => 'زنبور عسل', 'icon' => null],
            ['title' => 'آبزیان', 'slug' => 'aquaculture', 'model_type' => Product::class, 'order' => 8, 'page_title' => 'آبزیان', 'icon' => null],
            ['title' => 'خدمات دامپزشکی', 'slug' => 'vet-services', 'model_type' => \App\Models\Service::class, 'order' => 9, 'page_title' => 'خدمات دامپزشکی', 'icon' => null],
            ['title' => 'تغذیه دام', 'slug' => 'animal-feed', 'model_type' => Product::class, 'order' => 10, 'page_title' => 'تغذیه دام', 'icon' => 'files/gavo-goosfand-baham.jpg'],
        ];

        foreach ($categories as $category) {
            DB::table('categories')->updateOrInsert(
                ['slug' => $category['slug']],
                [
                    'title' => $category['title'],
                    'slug' => $category['slug'],
                    'model_type' => $category['model_type'],
                    'order' => $category['order'],
                    'url' => '/' . $category['slug'],
                    'icon' => $category['icon'],
                    'meta_title' => null,
                    'meta_desc' => null,
                    'meta_keywords' => null,
                    'desc' => null,
                    'page_title' => $category['page_title'],
                    'level' => 0,
                    'created_at' => now(),
                    'updated_at' => now(),
                    'created_by' => $adminId,
                ]
            );
        }
    }
}
