<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Traits\HasRoles;
use App\Models\User;

class UserSeeder extends Seeder
{
    // Call trait
    use HasRoles;
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Tableau de users
        $appUser = collect([
            // Dev
            [
                'first_name' => 'Romaric Eymard',
                'last_name' => 'Ouangni',
                'email'     => 'romaric.ouangni@car-rent.com',
                'phone'     => '2250101010101',
                'password'  => Hash::make('@password-10'),
                'active'    => 1,
            ],
            [
                'first_name' => 'Simon pièrre',
                'last_name' => 'Kossonou',
                'email'     => 'simon.koussonou@car-rent.com',
                'phone'     => '2250202020202',
                'password'  => Hash::make('@password-10'),
                'active'    => 1,
            ],
            [
                'first_name' => 'Baby',
                'last_name' => 'Location',
                'email'     => 'baby.location@baby-location.com',
                'phone'     => '2250202020201',
                'password'  => Hash::make('@password-10'),
                'active'    => 1,
            ],
        ]);

        // Insérer ou mettre à jour les utilisateurs
        foreach ($appUser as $user) {
            User::updateOrCreate(
                ['phone' => $user['phone']], // Cherche une entrée avec ce nom
                [
                    'first_name'    => $user['first_name'],
                    'last_name'     => $user['last_name'],
                    'email'         => $user['email'],
                    'password'      => $user['password'],
                    'active'        => $user['active'],
                    'created_at'    => Date('Y-m-d H:i:s'),
                ]
            );
        }
    }
}
