<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Hash;

use Database\Seeders\ActivitySeeder;
use Database\Seeders\CheckInSeeder;
use Database\Seeders\PrizeSeeder;
use Database\Seeders\RecipientsSeeder;

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents;
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $admin = ["3520","3444","3606"];
        User::truncate();

        $json = File::get("database/MAA.json");
        $countries = json_decode($json);

        foreach ($countries as $key => $value) {
            $role = in_array($value->user_id, $admin) ? "Admin" : "User";
            $role = $value->department_id == "xxx" ? "host" : $role;
            User::create([
                'user_id' => $value->user_id,
                'name' => $value->name,
                'department_id' => $value->department_id,
                'password' => Hash::make($value->user_id),
                'email' => $value->user_id." ".$value->name."/maa",
                'account' => "maa".$value->user_id,
                'role' => $role,
            ]);

        }

        $this->call([
            ActivitySeeder::class,
            CheckInSeeder::class,
            //PrizeSeeder::class,
            //RecipientsSeeder::class,
            DepartmentSeeder::class,
        ]);
    }
}
