<?php

namespace Database\Seeders;

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

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $admin = User::factory()->create([
            'document' => '00000001',
            'email' => 'admin@setelsat.com',
            'name' => 'Admin',
            'paternal_surname' => 'Sistema',
            'maternal_surname' => 'Setelsat',
            'phone' => '999999999',
            'password' => bcrypt('admin123'),
            'status' => true,
        ]);
        $admin->roles()->attach(Role::query()->where('name', 'Administrador')->firstOrFail()->id);

        $nocPrincipal = User::factory()->create([
            'document' => '00000002',
            'email' => 'noc@setelsat.com',
            'name' => 'Carlos',
            'paternal_surname' => 'Mendoza',
            'maternal_surname' => 'García',
            'phone' => '998888888',
            'password' => bcrypt('password123'),
            'status' => true,
        ]);
        $nocPrincipal->roles()->attach(Role::query()->where('name', 'NOC')->firstOrFail()->id);

        $tecnicoPrincipal = User::factory()->create([
            'document' => '00000003',
            'email' => 'tecnico@setelsat.com',
            'name' => 'Juan',
            'paternal_surname' => 'Rojas',
            'maternal_surname' => 'López',
            'phone' => '997777777',
            'password' => bcrypt('password123'),
            'status' => true,
        ]);
        $tecnicoPrincipal->roles()->attach(Role::query()->where('name', 'Técnico')->firstOrFail()->id);

        $coordinadorPrincipal = User::factory()->create([
            'document' => '00000004',
            'email' => 'coordinador@setelsat.com',
            'name' => 'María',
            'paternal_surname' => 'Torres',
            'maternal_surname' => 'Pérez',
            'phone' => '996666666',
            'password' => bcrypt('password123'),
            'status' => true,
        ]);
        $coordinadorPrincipal->roles()->attach(Role::query()->where('name', Role::COORDINATOR_NAME)->firstOrFail()->id);

        $nocRole = Role::query()->where('name', 'NOC')->firstOrFail();
        User::factory(10)->create()->each(fn (User $user) => $user->roles()->attach($nocRole->id));

        $tecnicoRole = Role::query()->where('name', 'Técnico')->firstOrFail();
        User::factory(20)->create()->each(fn (User $user) => $user->roles()->attach($tecnicoRole->id));

        $coordinadorRole = Role::query()->where('name', Role::COORDINATOR_NAME)->firstOrFail();
        User::factory(5)->create()->each(fn (User $user) => $user->roles()->attach($coordinadorRole->id));
    }
}
