<?php

declare(strict_types=1);

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\Menu;
use App\Models\User;
use Illuminate\Database\Seeder;

class MenusTableCategoriesSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        $admin = User::role('admin')->first();

        $categoriesMenu = Menu::updateOrCreate(
            ['title' => 'همه دسته بندی‌ ها'],
            [
                'url' => '',
                'order_id' => 0,
                'icon' => '',
                'created_by' => $admin->id,
                'parent_id' => null,
            ]
        );

        $digitalMenu = Menu::updateOrCreate(
            ['title' => 'کالای دیجیتال'],
            [
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
                'parent_id' => $categoriesMenu->id,
            ]
        );

        $fashionMenu = Menu::updateOrCreate(
            ['title' => 'مد و پوشاک'],
            [
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
                'parent_id' => $categoriesMenu->id,
            ]
        );

        $homeMenu = Menu::updateOrCreate(
            ['title' => 'خانه و آشپزخانه'],
            [
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
                'parent_id' => $categoriesMenu->id,
            ]
        );

        $digitalChildren = [
            [
                'title' => 'موبایل',
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'لپ تاپ',
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'تبلت',
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
        ];

        $fashionChildren = [
            [
                'title' => 'مردانه',
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'زنانه',
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'بچگانه',
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
        ];

        $homeChildren = [
            [
                'title' => 'لوازم خانگی برقی',
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'سرویس و ظروف آشپزخانه',
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'دکوراتیو',
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
        ];

        foreach ($digitalChildren as $child) {
            Menu::updateOrCreate(
                ['title' => $child['title']],
                array_merge($child, ['parent_id' => $digitalMenu->id])
            );
        }

        foreach ($fashionChildren as $child) {
            Menu::updateOrCreate(
                ['title' => $child['title']],
                array_merge($child, ['parent_id' => $fashionMenu->id])
            );
        }

        foreach ($homeChildren as $child) {
            Menu::updateOrCreate(
                ['title' => $child['title']],
                array_merge($child, ['parent_id' => $homeMenu->id])
            );
        }
    }
}
