<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\CheckIn;
use Illuminate\Support\Facades\File;

class CheckInSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        CheckIn::truncate();
        $json = File::get("database/MAA.json");
        $countries = json_decode($json);

        foreach ($countries as $key => $value) {
            if ($value->department_id != 'xxx') {
                switch ($value->department_id) {
                    case 'B00':
                        $region = '南區';
                        break;
                    case 'B10':
                        $region = '中區';
                        break;
                    default:
                        $region = '北區';
                }
                CheckIn::create([
                    'user_id' => $value->user_id,
                    'name' => $value->name,
                    'department_id' => $value->department_id,
                    'region' => $region,
                    'is_checked_in' => true,
                    'activity_id' => 1,
                    'created_at' => now(),
                    'updated_at' => now(),
                ]);
            }
        }
        CheckIn::create([
            'user_id' => 'A100',
            'name' => '來賓1000',
            'department_id' => null,
            'region' => '來賓',
            'is_checked_in' => true,
            'activity_id' => 1,
            'created_at' => now(),
            'updated_at' => now(),
        ]);
    }
}
