<?php

namespace Database\Seeders;

use App\Models\Admin;
use App\Models\Persona;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class AdminsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    private $data = [
        [
            'id' => 1,
            'nombre' => 'Soporte',
            'apellido' => 'Xnet',
            'admin' => [
                'root' => true,
                'username' => 'soportexnet',
                'email' => 'soporte@xnet.com.py',
                'password' => '$2y$10$7QIIv1cq.fUtzCCeVHhOy.6uvyOmNy9dsM.lbyXYaSIX3Laslg0I6',            ]
        ]
    ];

    public function run()
    {
        foreach ($this->data as $item) {
            $input = $item;
            unset($input['admin']);

            $result = Persona::firstOrCreate(
                ['id' => $input['id']],
                $input
            );

            $admin = array_merge($item['admin'], [
                'persona_id' => $result->id
            ]);

            Admin::firstOrCreate(
                ['email' => $admin['email']],
                $admin
            );
        }
    }
}
