<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Modules\Auth\Entities\User;
use Modules\Role\Entities\Role;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        $user = User::updateOrCreate(
            ['email' => 'ismail@developer.com'],
            [
                'name' => 'DEVELOPER',
                'phone_number' => '0123456789',
                'password' => bcrypt('Topazthegoat'),
                'status' => 'active',
            ]
        );

        // Find the DEVELOPER role
        $developerRole = Role::findByName('DEVELOPER', 'api');

        if (! $user->hasRole('DEVELOPER')) {
            $user->assignRole($developerRole);
            $this->command->info('DEVELOPER role assigned to user: '.$user->email);
        } else {
            $this->command->info('User already has DEVELOPER role: '.$user->email);
        }
    }
}
