<?php

namespace Database\Seeders;

use App\Models\Alumno;
use App\Models\User;
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        $faker = Faker::create('es_MX');

        $user = User::create([
            'name'=>'Luis Fernando',
            'apellidoPaterno'=>'Pérez',
            'apellidoMaterno'=>'Luna',
            'email'=>'fernandoestrp@outlook.es',
            'direccion'=>'Zacatenco mz 21 lt 2 san francisco cuautliquixca',
            'telefono'=>'5636287759',
            'password' => bcrypt('6686'),
            'code'=>1,
            'status'=>1
        ])->assignRole('Administrador');

        $user->plantelUsuarios()->sync(3);

        $user1 = User::create([
            'name'=>'Crokly',
            'apellidoPaterno'=>'real',
            'apellidoMaterno'=>'Luna',
            'email'=>'fernandoestr61@gmail.com',
            'direccion'=>'Zacatenco mz 21 lt 2 san francisco cuautliquixca',
            'telefono'=>'5636287760',
            'password' => bcrypt('6686'),
            'code'=>1,
            'status'=>1
        ])->assignRole('Control escolar');

        $user1->plantelUsuarios()->sync(3);

        for ($e = 1; $e <= 2; $e++) {
            for ($i = 1; $i <= 15; $i++) {

                $usr = User::create([
                    'name' => $faker->firstName(),
                    'apellidoPaterno' => $faker->lastName(),
                    'apellidoMaterno' => $faker->lastName(),
                    'email' => $faker->unique()->safeEmail(),
                    'direccion' => $faker->address(),
                    'telefono' => $faker->numerify('55########'),
                    'password' => bcrypt('6686'),
                    'code' => 0,
                    'status' => 1
                ])->assignRole('Alumno');

                $usr->plantelUsuarios()->sync([3]);

                $alumno = Alumno::create([
                    'nivel' => $e,
                    'plan_id' => $e,
                    'ciclo' => 3,
                    'turno' => 1,
                    'medio' => 1,
                    'usuario_registro' => 1,
                    'plane_id' => 0,
                    'status' => 1
                ]);

                $alumno->alumnos()->sync($usr->id);
            }
        }
    }
}
