<?php

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;

use App\Models\Guard;
use App\Models\Login;
use App\Models\Staff;
use App\Models\Visitor;
use App\Models\VisitorLog;
use App\Models\VisitLocation;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

class DummyData extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {

        // staff
        $staffDataArray = [
            [
                'name' => 'admin_1',
                'tel_no' => '',
                'position' => '',
                'department' => 'IT',
            ],
            [
                'name' => 'admin_2',
                'tel_no' => '',
                'position' => '',
                'department' => 'IT',
            ]
        ];

        foreach ($staffDataArray as $staffDataIndex => $staffData) {
            $staffResult = Staff::create($staffData);
            $loginResult = Login::create([
                'id_staff' => $staffResult->id,
                'username' => $staffResult->name,
                'password' => Hash::make('password'),
            ]);
        }

        // guard
        $guardDataArray = [
            [
                'name' => 'guard_1',
            ],
            [
                'name' => 'guard_2',
            ]
        ];

        foreach ($guardDataArray as $guardDataIndex => $guardData) {
            $guardResult = Guard::create($guardData);
            $loginResult = Login::create([
                'id_guard' => $guardResult->id,
                'username' => $guardResult->name,
                'password' => Hash::make('password'),
            ]);
        }

        // visitor
        $visitorDataArray = [
            [
                'name' => 'visitor_1',
                'ic' => '000000000000',
                'tel_no' => '0123456789',
            ],
            [
                'name' => 'visitor_2',
                'ic' => '000000000000',
                'tel_no' => '0123456789',
            ]
        ];

        foreach ($visitorDataArray as $visitorDataIndex => $visitorData) {
            $guardResult = Visitor::create($visitorData);
        }

        // visitor log
        $visitorLogDataArray = [
            [
                'id_staff' => Staff::inRandomOrder()->first()->id,
                'id_visitor' => Visitor::inRandomOrder()->first()->id,
                'id_guard_in' => Guard::inRandomOrder()->first()->id,
                'id_guard_out' => Guard::inRandomOrder()->first()->id,
                'purpose' => 'Parcel Delivery',
                'plate_no' => 'VHX1234',
                'total_visitor' => '1',
                'arrive_at' => '2024-08-06 10:00:00',
                'depart_at' => '2024-08-06 12:00:00'
            ],
            [
                'id_staff' => Staff::inRandomOrder()->first()->id,
                'id_visitor' => Visitor::inRandomOrder()->first()->id,
                'id_guard_in' => Guard::inRandomOrder()->first()->id,
                'id_guard_out' => Guard::inRandomOrder()->first()->id,
                'purpose' => 'Parcel Delivery',
                'plate_no' => 'WHY5678',
                'total_visitor' => '1',
                'arrive_at' => '2024-08-07 12:00:00',
                'depart_at' => '2024-08-07 15:00:00'
            ],
            [
                'id_staff' => Staff::inRandomOrder()->first()->id,
                'id_visitor' => Visitor::inRandomOrder()->first()->id,
                'id_guard_in' => Guard::inRandomOrder()->first()->id,
                'id_guard_out' => Guard::inRandomOrder()->first()->id,
                'purpose' => 'Meeting',
                'plate_no' => 'PPY5678',
                'total_visitor' => '3',
                'arrive_at' => '2024-08-09 15:00:00',
                'depart_at' => null

            ]
        ];

        foreach ($visitorLogDataArray as $visitorLogDataIndex => $visitorLogData) {
            $visitorLogResult = VisitorLog::create($visitorLogData);
        }

        // VisitLocation
        $visitLocationArray = [
            [
                'location' => 'BLOCK A',
            ],
            [
                'location' => 'BLOCK B',
            ],
        ];

        foreach ($visitLocationArray as $visitLocationIndex => $visitLocation) {
            $visitLocationResult = VisitLocation::create($visitLocation);
        }
    }
}
