<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // Crear Roles
        $adminRole = Role::firstOrCreate(['name' => 'Admin']);
        $sellerRole = Role::firstOrCreate(['name' => 'Vendedor']);
        $warehouseRole = Role::firstOrCreate(['name' => 'Almacenero']);
        $investorRole = Role::firstOrCreate(['name' => 'Inversor']);

        // Crear cuenta de Administrador principal
        $admin = User::updateOrCreate(
            ['email'    => 'admin@ventas.com'],
            [
                'name'     => 'Administrador',
                'password' => bcrypt('password'),
                'is_active' => true,
            ]
        );
        $admin->assignRole($adminRole);

        // Crear una cuenta de Vendedor de prueba
        $seller = User::updateOrCreate(
            ['email'    => 'vendedor@ventas.com'],
            [
                'name'     => 'Vendedor Prueba',
                'password' => bcrypt('password'),
                'is_active' => true,
            ]
        );
        $seller->assignRole($sellerRole);

        // Cargar categorías, configuraciones y promociones
        $this->call([
            CategorySeeder::class,
            SettingSeeder::class,
            PromotionSeeder::class,
        ]);
    }
}
