<?php

namespace Database\Seeders;

use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        $this->call([
            RolesAndPermissionsSeeder::class,
            SettingsSeeder::class,
            SpaceTypeSeeder::class,
            ProductCategorySeeder::class,
            EventTypeSeeder::class,
        ]);

        $adminRole = Role::query()->where('slug', 'system-administrator')->first();

        $admin = User::query()->updateOrCreate(
            ['email' => 'admin@venue.local'],
            [
                'name' => 'System Administrator',
                'phone' => null,
                'password' => Hash::make('password'),
                'is_active' => true,
                'email_verified_at' => now(),
            ],
        );

        if ($adminRole !== null) {
            $admin->roles()->sync([$adminRole->id]);
        }
    }
}
