<?php

namespace Database\Seeders;

use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $input =[
            'name' => 'Administrator',
                'email' => 'admin@iaea.com',
                'password' => Hash::make('admin@iaea.com')
        ];
         DB::transaction(function () use ($input) {
             tap(User::create([
                'first_name' => $input['name'],
                'email' => $input['email'],
                'password' => $input['password'],
            ]), function (User $user) {
                $this->createTeam($user);
            });
        });
    }

    protected function createTeam(User $user)
    {
        $user->ownedTeams()->save(Team::forceCreate([
            'user_id' => $user->id,
            'name' => "Engineers",
            'personal_team' => true,
        ]));

        $user->ownedTeams()->save(Team::forceCreate([
            'user_id' => $user->id,
            'name' => "Front Desk",
            'personal_team' => true,
        ]));

        $user->ownedTeams()->save(Team::forceCreate([
            'user_id' => $user->id,
            'name' => "Users",
            'personal_team' => true,
        ]));

        
    }
    
}
