<?php

namespace Database\Seeders;

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

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents;

    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        $this->call(RolesAndPermissionsSeeder::class);

        // Super Admin
        $superAdmin = \App\Models\User::updateOrCreate(
            ['email' => 'admin@itsystem.com'],
            [
                'name'           => 'Super Admin',
                'password'       => bcrypt('Admin@123456'),
                'is_super_admin' => true,
                'is_active'      => true,
                'tenant_id'      => null,
            ]
        );

        // Demo Tenant
        $tenant = \App\Models\Tenant::updateOrCreate(
            ['slug' => 'demo-company'],
            [
                'name'      => 'Demo Company',
                'email'     => 'info@demo.com',
                'is_active' => true,
            ]
        );

        // Demo Company Admin
        $companyAdmin = \App\Models\User::updateOrCreate(
            ['email' => 'company@demo.com'],
            [
                'name'       => 'Company Admin',
                'password'   => bcrypt('Admin@123456'),
                'tenant_id'  => $tenant->id,
                'is_active'  => true,
                'is_super_admin' => false,
            ]
        );
        $companyAdmin->assignRole('company-admin');
    }
}
